求大神指點,謝謝
不是前邊應該加上整形(int)嗎??int three = one + two;
??????? System.out.println("three = one +two ==>"+three);
??????? int three += one;
??????? System.out.println("three += one ==>"+three);
??????? int three -= one;
???????? System.out.println("three -= one ==>"+three);
??????? int three *= one;
??????? System.out.println(" three *= one ==>"+three);
??????? int three /= one;
???????? System.out.println(" three /= one ==>"+three);
??????? int three %= one;
??????? System.out.println(" three %= one ==>"+three);
?????? ?
???????
2017-03-30
我試著理解一下你的問題哈(被前面的有點暈)
1、你可能問的是是否需要對結果進行強制轉換?
答:沒關系的,int和int類型進行計算,結果默認也是int類型,所以不需要
2、你可能問的是為什么計算的時候不在前面加int對吧?
紅框里面這些呢,實際上是不對的,在編譯器里是無法通過的。
在一個方法體里,同一個變量名只能定義一次。
對于three在最開始已經定義過一次了。之后直接用three + = one;就可以了,不需要int three+ = one;
2017-03-30
整型值做計算,最后結果也會是int整形,不需要再強轉
2017-03-30
本來就是整形??不需要