Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class QA7230586 {
- public static void main(String[] args) {
- Scanner in = new Scanner(System.in);
- int goal = new Random().nextInt(100);
- for (int trial = 1; ; trial++) {
- System.out.print("Shoot number: ");
- if (!in.hasNextLine()) {
- in.close();
- break;
- }
- int shoot;
- try {
- shoot = new Integer(in.nextLine());
- }
- catch (Exception e) {
- trial--;
- continue;
- }
- if (shoot < goal) {
- System.out.println("small");
- continue;
- }
- if (shoot > goal) {
- System.out.println("big");
- continue;
- }
- System.out.println("Success, " + trial + " trials");
- break;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement