为了账号安全,请及时绑定邮箱和手机立即绑定

请问为什么得出的结果全都是30 ?啥意思啊

package com.waiting;


public class Test {

public static void main(String[] args) {

        int one = 10 ;

        int two = 20 ;

        int three = 0 ;

        three=one+two;

        three+=one;

        three-=one;

        three*=one;

        three/=one;

        System.out.println("three=one+two==>"+three);

        System.out.println("three+=one==>"+three);

        System.out.println("three-=one==>"+three);

        System.out.println("three*=one==>"+three);

        System.out.println("three/=one==>"+three);

        System.out.println("three%=one==>"+three);

请问 有人帮我解答下吗?这个代码是不是应该这样写?结果怎么全都是最后一个数  30  30  30 3 0.。。。。啥意思啊

正在回答

3 回答

你好,这么写:

public class HelloWorld{
    public static void main(String[] args) {
	    int one = 10 ;
        int two = 20 ;
        int three = 0 ;
        three = one +two;
        System.out.println("three = one + two ==>" + three);
        three += one;
        System.out.println("three += one ==>" + three);
        three -= one;
        System.out.println("three -= one ==>" + three);
        three *=one;
        System.out.println("three *= one ==>" + three);
        three /=one;
        System.out.println("three /= one ==>" + three);
        three %=one;
        System.out.println("three %= one ==>" + three);   
	}
}

你的问题是把所有的运行语句执行后,最后输出的,肯定结果都一样,应该执行一条输出一条,不然后会覆盖,

望楼主采纳!

2 回复 有任何疑惑可以回复我~
#1

hurry_君君 提问者

嘻嘻嘻 谢谢 了解啦!!!! I pray for you
2016-01-09 回复 有任何疑惑可以回复我~
#2

hurry_君君 提问者

非常感谢!
2016-01-09 回复 有任何疑惑可以回复我~
#3

听那风的声音

为什么第6行不添加数据类型符号?
2016-01-20 回复 有任何疑惑可以回复我~
#4

westlife

能详细解释下吗?先谢谢了!
2016-04-25 回复 有任何疑惑可以回复我~
查看1条回复

只输出最后的结果,如果想把每一步的结果都输出,那么要在每一步后面都有个sysout

0 回复 有任何疑惑可以回复我~
#1

hurry_君君 提问者

嘻嘻嘻 谢谢 了解啦!!!! pray for you
2016-01-09 回复 有任何疑惑可以回复我~

肯定是30,只输出最后一个计算结果

 int one = 10 ;
        int two = 20 ;
        int three = 0 ;
        three=one+two;System.out.println("three=one+two==>"+three);
        three+=one;System.out.println("three+=one==>"+three);
        three-=one;System.out.println("three-=one==>"+three);
        three*=one;System.out.println("three*=one==>"+three);
        three/=one;System.out.println("three/=one==>"+three);


0 回复 有任何疑惑可以回复我~
#1

hurry_君君 提问者

嘻嘻嘻 谢谢 了解啦!!!! pray for you
2016-01-09 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消

请问为什么得出的结果全都是30 ?啥意思啊

我要回答 关注问题
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号