// a simple do-while-loop example. // keeps insulting the user until the user indicates he/she has had enough // Specifically, this loop continues as long as the user types 'n' or 'N' // to indicate "No". Anything else causes the loop to quit. import java.util.Scanner; class Insult2 { public static void main(String[] args) { Scanner s = new Scanner(System.in); String buf; char response; // declare (but not initialized) do { System.out.println("Hey you! You at the keyboard! You're a jerk!!!"); System.out.print("Have you had enough (y/n)? "); buf = s.next(); // get response as a string response = buf.charAt(0); // response is the first letter } while (response == 'n' || response == 'N'); // control condition System.out.println("Have a nice day."); } }