Я смотрю на свой компьютер два часа, и я не могу понять, что я делаю неправильно. Может ли кто-нибудь помочь мне увидеть свет?Ошибка при кодировании при попытке цикла while
package blackjack;
import java.util.Random;
import java.util.Scanner;
/**
*
*
*/
public class whileloop
{
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
}
// declare a variable
int human;
int computer;
int computerTotal=0;
int humanTotal=0;
Random randomNumber = new Random();
Scanner keyboatrd = new Scanner(System.in);
while((computerTotal < 21) && (humanTotal < 21))
{
computer = randomNumber.nextInt(11) + 1;
computerTotal = computerTotal + computer;
human= randomNumber.nextInt(11) + 1;
humanTotal=humanTotal+human;
}
if(computerTotal == 21)
{
System.out.println("computer total=" + computerTotal);
System.out.println("human total=" + humanTotal);
System.out.println("AI wins.");
else if (humanTotal == 21)
{
System.out.println("computer total =" + computerTotal);
System.out.println("human total=" + humanTotal);
System.out.println("Human wins.");
} else if ((computerTotal < 21) && (humanTotal > 21))
{
System.out.println("computer total=" + computerTotal);
System.out.println("human total=" + humanTotal);
System.out.println("AI wins.");
}
else if ((computerTotal > 21) && (humanTotal > 21))
{
System.out.println("computer total=" + computerTotal);
System.out.println("human total=" + humanTotal);
System.out.println("human wins.");
}
else
{
System.out.println("computer total=" + computerTotal);
System.out.println("human total=" + humanTotal);
System.out.println("No winner.");
}
}
}
hint main method {}. – Satya
Формат вашего кода красиво, и вы увидите проблему, которая заключается в открытии или закрытии брекетов. Конечно, чтение текста ошибки также может помочь. –
Спасибо! Будучи новобранец уверен, сосет ... –