-1
프로그래밍에 익숙하지 않고 이전에 프로그램을 작성하는 데 문제가 있습니다. 추측하는 게임입니다. 사용자는 생성 된 임의의 숫자를 추측해야하며 6 개의 기회를 가질 수 있습니다. 불행하게도 나는 프로그램에 무엇이 잘못되었는지 이해하지 못한다. 프로그램을 시작하기 위해 "예"라고 입력 할 때마다 아무 일도 일어나지 않습니다. 아래 코드는 제가 잘못하고있는 것을 알려주고 있습니다.drJava에서 입력 한 후 프로그램이 실행되지 않습니다.
import java.util.Scanner;
import java.util.Random;
public class Project4{
public static void main(String[] args){
Scanner input = new Scanner(System.in);
System.out.println("Would you like to play a game? (Yes or No)");
String a1 = input.next().toLowerCase();
while(a1.equals("Yes")){
Random secretnum = new Random();
int num;
for(int counter=0; counter<2; counter++){
num = 1+secretnum.nextInt(99);
System.out.println("You have 6 chances to guess the secret number");
System.out.println("Player : guess a number between 1 and 100");
int num1 = input.nextInt();
while(num1 != num){
for(int i = 6; i < 0; i--){
if(num1 < num){
System.out.println("Sorry," + num1 + "is too low");
System.out.println("You have" + i + "strikes left");
}else{
if(num1 > num){
System.out.println("Sorry," + num1 + "is too high");
System.out.println("You have" + i + "strikes left");
}
}
if(num1 == num){
System.out.println("Correct! The secret number was" + secretnum);
}
}
if(num1 < 0 || num1 > 100){
for(int i = 6; i < 0; i--){
System.out.println("You were supposed to enter a number between 1 and 100");
System.out.println("You have" + i + "strikes left");
}
}
}
}
if(a1.equals("No"));
System.out.println("Goodbye");
}
input.close();
}
}
toLowerCase 방법이 무엇인지 아시나요? –
실제로이 제품에 익숙하지 않은 것은 무엇입니까? – Udaman