亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

求教這個three=one+two為什么要寫入?

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);

? ? ? ? }

既然已經賦予了three=0了、為什么還寫入、既然寫入前邊為什么不加入int

正在回答

2 回答

int three ?= 0既聲明了three又初始化賦值為0,后讓one和two加和賦值給three,再輸入three的值顯示在控制臺,這時候打印出來才是?three = one + two ==> 30,否則打印出來是?three = one + two ==> 0,與要求就不符合了

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

頭大頂天下 回復 慕娘1537045 提問者

因為現在是在進行運算,而不是在聲明一個新的變量出來,前面加string、int、char之類的都是在聲明變量的一個類型。
2017-02-08 回復 有任何疑惑可以回復我~

因為最開始已經賦予了three 變量類型int,就無需再加入int。

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

慕娘1537045 提問者

適用于其他所有類型么
2017-02-05 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消

求教這個three=one+two為什么要寫入?

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號