12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- import java.util.Scanner;
- import java.util.Random;
-
- public class Main {
-
- public static void main(String[] args){
- Random ran = new Random();
- Scanner input = new Scanner(System.in);
-
- int value = ran.nextInt(10);
- int count = 0;
- int guess = 0;
-
-
-
-
-
- while(true){
- System.out.println("Please enter a number between 1 to 10 inclusive:");
- guess = input.nextInt();
- count++;
- if(guess < 1 || guess > 10){
- System.out.println("Invalid input");
- }
-
- else if(guess < value){
- System.out.println("Too small");
- System.out.println("Please guess a number again between 1 to 10");
- }
- else if(guess > value){
- System.out.println("Too large");
- System.out.println("Please guess a number again between 1 to 10");
- }
- else if(guess == value){
- System.out.println("correct guess!");
- System.out.println("You guessed the ans in " + count + " attempts!");
- break;
- }
-
-
- }
-
-
- }
- }
|