Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.lang.Math;
- import java.util.Random;
- import java.util.Scanner;
- public class mainclass
- {
- public static void main(String[] args)
- {
- Random r = new Random();
- Scanner s = new Scanner(System.in);
- int randNum = r.nextInt(101);
- int guess;
- int tries = 0;
- do
- {
- System.out.print("Guess the number between 1 - 100: ");
- guess = s.nextInt();
- if(guess < randNum)
- {
- System.out.println("Higher.");
- }
- else if(guess > randNum)
- {
- System.out.println("Lower.");
- }
- else if(guess == randNum)
- {
- System.out.printf("You guessed the right number! " + "It was " + randNum, ". " + "You made it in " + tries + " tries." );
- }
- tries += 1;
- }
- while(guess != randNum);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement