請(qǐng)教:這樣為什么不對(duì)呢????
public class HelloWorld {
? ??
? ? // 定義靜態(tài)變量score1
? ? static int score1 = 86;
? ? // 定義靜態(tài)變量score2
static int score2 = 92;?
? ? // 定義靜態(tài)方法sum,計(jì)算成績(jī)總分,并返回總分
public ?static ? int sum(i,j) {?
? ? ? return i+j;? ?
}
public static void main(String[] args) {
? ? ? ??
? ? ? ? // 調(diào)用靜態(tài)方法sum并接收返回值
int allScore = HelloWorld.sum(score1,score2);
? ? ? ??
System.out.println("總分:" + allScore);
}
}
2015-10-30
你好像是學(xué)過C的,形參必須指定其類型,另外,由于score1和score2是成員變量可以直接被該類中的方法和其他類中的方法調(diào)用,所以不需要把sum變成有參方法,直接在方法中調(diào)用。
2015-09-15
i 和j 前面加參數(shù)類型 int
2015-08-25
方法貌似要給傳入?yún)?shù)類型吧