// CS7 // readChar() behaves a bit differently than the other reading // methods in tio. In short, it counts whitespace as a char, meaning // that goofy things can happen. // // The program below runs fine, but to see the difference, try commenting // out the readLine() and re-run it. You'll quickly see how it screws // up. import tio.*; public class userLoop { public static void main(String [] args) { char answer='y'; int n; while (answer=='y' || answer=='Y') { System.out.print("Enter an integer: "); n = Console.in.readInt(); System.out.println("Thanks for the " + n); System.out.print("Would you like to go again? (y/n) "); Console.in.readLine(); // flushes the buffer answer = (char) Console.in.readChar(); } } } /* SAMPLE OUTPUT: Enter an integer: 4 Thanks for the 4 Would you like to go again? (y/n) y Enter an integer: 2 Thanks for the 2 Would you like to go again? (y/n) y Enter an integer: 100 Thanks for the 100 Would you like to go again? (y/n) n */