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

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

我能問這樣寫過不了,是什么原因嗎?

public class HelloWorld { ? ? ?// 定義靜態變量score1 ? ?static int score1 = 86; ? ?// 定義靜態變量score2 static int score2 = 92; ? ?// 定義靜態方法sum,計算成績總分,并返回總分 public ? static ?int sum() { ? ? ? ? ?return (score1+score2); } }

正在回答

3 回答

加上主方法:

public static void main(){

? ? int sum = HelloWorld.sum();

? ? System.out.println("總分:"+sum);

}

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

慕雪8357630 提問者

非常感謝!
2017-06-19 回復 有任何疑惑可以回復我~

因為你的返回值沒有東西接收啊,int S=sum();System.out.println(S);這樣子就可以了。

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

public class HelloWorld {

// 定義靜態變量score1

???? static int score1 = 86; ? ?// 定義靜態變量score2

???? static int score2 = 92; ? ?// 定義靜態方法sum,計算成績總分,并返回總分?

???? public static int sum() {

???????? return (score1+score2);?

???? }?

???? public static void main(String[] args) {

???? System.out.println(sum());

????}

}



//返回值要有輸出才能有顯示

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

舉報

0/150
提交
取消

我能問這樣寫過不了,是什么原因嗎?

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

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

幫助反饋 APP下載

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

公眾號

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