0
我想在我的遊戲中做一個for循環,使得當猜數的數量加起來後,它進入for循環,並給出正確的猜測數。這是爲了我的計算機科學課,我們必須將for循環合併到程序中。For循環在我的策劃遊戲
if (guess1 == Secret_code[0]) {
System.out.println(" You have guessed one correctly in the right spot!");
}
if (guess2 == Secret_code[1]) {
System.out.println(" You have guessed one correctly in the right spot!");
}
if (guess3 == Secret_code[2]) {
System.out.println(" You have guessed one correctly in the right spot!");
}
if (guess4 == Secret_code[3]) {
System.out.println(" You have guessed one correctly in the right spot!");
}
do {
System.out.println("What is the number one peg in my code???");
guess1 = Guess.nextInt();
System.out.println("What is the number two peg in my code???");
guess2 = Guess.nextInt();
System.out.println("What is the number three peg in my code???");
guess3 = Guess.nextInt();
System.out.println("What is the number four peg in my code???");
guess4 = Guess.nextInt();
if (guess1 == Secret_code[0]) {
System.out.println(" You have guessed one correctly in the right spot!");
}
if (guess2 == Secret_code[1]) {
System.out.println(" You have guessed one correctly in the right spot!");
}
if (guess3 == Secret_code[2]) {
System.out.println(" You have guessed one correctly in the right spot!");
}
if (guess4 == Secret_code[3]) {
System.out.println(" You have guessed one correctly in the right spot!");
}
}
while ((guess1 != Secret_code[0]) & (guess2 != Secret_code[1]) & (guess3 != Secret_code[2]) & (guess4 != Secret_code[3]));
public static void CorrectGuess(int[] Secret_code) {
//Variables
int Correctspot;
for (Secret_code[0] = 0; Secret_code[0] < 3; Secret_code[0]++)
Correctspot = +1;
}
有什麼問題? –
沒有問題....只需要添加for循環,可以計算正確的猜測數 – Sot
本網站不適用於代碼請求。當你遇到問題時,你會來到這裏,通常會展示你對這個主題的嘗試或任何研究。如果你不瞭解情況,請告訴你的老師,因爲他們是那些得到報酬以確保你知道這些東西的人,如果他們不知道你是否有什麼東西,就不能正確教導你不明白 –