Untitled

mail@pastecode.io avatar
unknown
java
a year ago
843 B
7
Indexable
Never
package myfirstjava;
import java.util.Scanner;
import java.util.Random;

public class Main {
	
	
    public static void main(String[] args) {
    	Scanner scanner = new Scanner(System.in);
    
    	Random random = new Random();
    	int randomNumber = random.nextInt(100) + 1;
    	int attempts = 0;
    	
    	System.out.println("Welcome to guess the number");
    	
    	
    	while(true) {
    		System.out.println("Your guess: ");
        	int input1 = Integer.valueOf(scanner.nextLine());
    		attempts++;
    		
    		if(input1 < randomNumber) {
    			System.out.println("Its below, try again");
    		}
    		else if(input1 > randomNumber) {
    			System.out.println("Its above, try again");
    		}
    		else if(input1 == randomNumber) {
    			System.out.println("You passed");
    			break;
    		}
    	}
 
    }           	
 }