Advertisement
cd62131

qa7230586 big or small

Oct 18th, 2013
419
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 0.75 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. public class QA7230586 {
  4.   public static void main(String[] args) {
  5.     Scanner in = new Scanner(System.in);
  6.     int goal = new Random().nextInt(100);
  7.     for (int trial = 1; ; trial++) {
  8.       System.out.print("Shoot number: ");
  9.       if (!in.hasNextLine()) {
  10.         in.close();
  11.         break;
  12.       }
  13.       int shoot;
  14.       try {
  15.         shoot = new Integer(in.nextLine());
  16.       }
  17.       catch (Exception e) {
  18.         trial--;
  19.         continue;
  20.       }
  21.       if (shoot < goal) {
  22.         System.out.println("small");
  23.         continue;
  24.       }
  25.       if (shoot > goal) {
  26.         System.out.println("big");
  27.         continue;
  28.       }
  29.       System.out.println("Success, " + trial + " trials");
  30.       break;
  31.     }
  32.   }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement