/** * A simple intelligence test (with correctness check) */ import javax.swing.*; public class SimpleTest2 { public static void main( String[ ] args ) { boolean isCorrect; do { String choice = JOptionPane.showInputDialog( "What is the world's greatest university? (hint: UMCP)" ); if (choice.equals("UMCP")) { // correct response isCorrect = true; } else { // incorrect response isCorrect = false; JOptionPane.showMessageDialog(null, "You blew it. Try again."); } } while (!isCorrect); // keep trying until correct JOptionPane.showMessageDialog(null, "Wise choice."); System.exit(0); // terminate program } }