// from Lecture Notes 14 // http://silo.cs.indiana.edu:8346/c212/sum2016/exam02/0713a.phps import java.util.Scanner; public class GuessTheNumber { public static void main(String[] args) { String debug = args.length == 0 ? "" : args[0]; // [1] int secret = (int) (Math.random() * 100) + 1; int mistakes = 0; Scanner s = new Scanner(System.in); if (debug.equals("debug")) // [2] System.out.print("(" + secret + ") Type: "); else System.out.print("Type: "); String line = s.nextLine(); while (! line.equals("bye")) { int number = Integer.parseInt(line); if (number > secret) { mistakes += 1; if (mistakes < 6) System.out.println("Try lower."); else { System.out.println("You lost."); break; } } else if (number < secret) { mistakes += 1; if (mistakes < 6) System.out.println("Try higher."); else { System.out.println("You lost."); break; } } else { System.out.println("You won."); break; } if (debug.equals("debug")) // [3] System.out.print("(" + secret + ") Type: "); else System.out.print("Type: "); line = s.nextLine(); } } }