Advertisement
Guest User

Rachel - Java

a guest
Apr 21st, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.98 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class MyClass {
  4.     public static void main(String args[]) {
  5.         int random = (int)(Math.random() * 10 + 1);
  6.         int guess_count = 0;
  7.         System.out.println("Guess the number from 1 - 10");
  8.         int correct = 0;
  9.         int guess = 0;
  10.         System.out.println(random);
  11.         Scanner sc = new Scanner(System.in);
  12.         do{
  13.             System.out.print("Enter your number: ");
  14.             guess++;
  15.             //guess = sc.nextInt();
  16.             System.out.println(guess);
  17.            
  18.            
  19.             if(guess == random)
  20.             {
  21.                 correct = 1;
  22.             }
  23.             else if (guess < random){
  24.                 System.out.println("Higher");
  25.             }else if(guess > random){
  26.                 System.out.println("Lower");
  27.             }
  28.            
  29.            
  30.         }while(correct == 0);
  31.        
  32.         System.out.println("Congratulations! You guess the correct number");
  33.     }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement