[JAVA] [Personal memo] Number guessing game

I can't do what I was asked to do, so today I omitted some conditions that should be specified. All the errors that I didn't understand for the time being disappeared, and I'm happy to move: hotdog :: grinning:

package kazuate;

public class kazuate {


	public static void main(String[] args) {
		//Generate random numbers
		int Ran=new java.util.Random().nextInt(1000);

		//Game start statement.
		System.out.println("Number guessing game");
		System.out.println("Please enter a 3-digit integer");

		//Set the maximum number of games
		int Limit=5;

		//Below, while turning with a for statement, accepting 3-digit input, processing each time.

		for(int i=0;i<=Limit;i++) {
			int th = i + 2;

			//Set keyboard reception
			int yourN=new java.util.Scanner(System.in).nextInt();

			//Set the error code when the number is 0 or less or 1000 or more
			if(yourN>1000||yourN<0) {
				throw new IllegalArgumentException("Please set the number to be 100 or more and 999 or less.");
			}

			//Processing when the maximum number of games is reached. Congratulations on the last correct answer, otherwise the answer is displayed and the game ends
			if(Limit==th) {
				if(Ran==yourN) {
					System.out.println("I succeeded in the last challenge! !! Congrats! End the game");
				}else{
					System.out.println("Game over. The correct answer is"+Ran+"is");}
				break;}


			//Processing when the number received is larger than the random number
			else if(Ran<yourN) {
			System.out.println("The kazu is big. Please enter again");


			//Processing when the number received is smaller than the random number
			}else if(Ran>yourN) {
			System.out.println("Kazu is small Please enter again");

			//Processing when the answer is correct. Also displays the number of times you tried to get the correct answer
			}else if(Ran==yourN) {
				System.out.println((i+1)+"It's a success for the second time!");
				break;
			}
		}
		}
		}



Recommended Posts

[Personal memo] Number guessing game
Java number guessing game (standard programming problem)
C # (random number) memo
[Personal memo] About Spring framework
Personal memo Progate Ruby I (2)
Personal memo Eclipse plug-in installation
Personal memo Lombok's typical annotation
Personal memo Progate Ruby I (1)
Java HashMap, entrySet [Personal memo]
Personal memo: Metaprogramming with Java reflection
Ruby Learning # 22 Building a Guessing Game
Age guessing game made in Java
[Personal memo] How to interact with a random number generator in Java