請問為什么得出的結果全都是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.。。。。啥意思啊
2016-01-01
你好,這么寫:
你的問題是把所有的運行語句執行后,最后輸出的,肯定結果都一樣,應該執行一條輸出一條,不然后會覆蓋,
望樓主采納!
2016-01-02
只輸出最后的結果,如果想把每一步的結果都輸出,那么要在每一步后面都有個sysout
2016-01-01
肯定是30,只輸出最后一個計算結果