我是編程新手,無法確定如何在代碼的另一部分編寫代碼時調用方法。下面是整個代碼的一部分(不是所有的),但是我真的很感激,如果有人不僅可以糾正這個問題,而且可以解釋我做錯了什麼?我正在參加在線課程,教授有點難以聯繫!在Java中擲骰子分配:調用方法
while (x == 'y'){
int roll = 1;
System.out.println("Roll " + roll);
roll++;
System.out.println(RollTheDice(dA, dB));
}
}
public static int RollTheDice(int dA, int dB){
int A = (int)(Math.random() * 6 + 1);
int B = (int)(Math.random() * 6 + 1);
System.out.println(A + "\n" + B);
int sum = (A + B);
if (sum == 7)
System.out.println("Craps!" + "\n");
else if (sum == 2)
System.out.println("Sanke eyes!" + "\n");
else if (sum == 12)
System.out.println("Box cars!" + "\n");
return A + B;
}
'static'方法必須從'static'上下文中調用。 – Maroun
你需要粘貼整個代碼才能正確解釋給你! – Ritikesh
粘貼一個編譯,運行並解釋其行爲中出乎意料的程序。如果它不能編譯,請粘貼確切的錯誤。 –