

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


// EvenOdd.java Java Foundations // // Demonstrates the use of the JOptionPane class. //******************************************************************** import javax.swing.JOptionPane; public class EvenOdd { //----------------------------------------------------------------- // Determines if the value input by the user is even or odd. // Uses multiple dialog boxes for user interaction. //----------------------------------------------------------------- public static void main (String[] args) { String numStr, result; int num, again; do { numStr = JOptionPane.showInputDialog ("Enter an integer: "); num = Integer.parseInt(numStr); result = "That number is " + ((num%2 == 0)? "even" : "odd"); JOptionPane.showMessageDialog (null, result);
again = JOptionPane.showConfirmDialog (null, "Do Another?"); } while (again == JOptionPane.YES_OPTION); System.out.println("here"); }