Advertisement
Guest User

Rachel - Java

a guest
Apr 21st, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.95 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 = sc.nextInt();
  15.            
  16.            
  17.             if(guess == random)
  18.             {
  19.                 correct = 1;
  20.             }
  21.             else if (guess < random){
  22.                 System.out.println("Wrong! Higher pa bes\n");
  23.             }else if(guess > random){
  24.                 System.out.println("Wrong! Lower madam\n");
  25.             }
  26.            
  27.            
  28.         }while(correct == 0);
  29.        
  30.         System.out.println("\n\nCongratulations! You guess the correct number");
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement