Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Java Foundations: EvenOdd.java - Interactive Even or Odd Number Determination, Study Guides, Projects, Research of Java Programming

This java code demonstrates the use of joptionpane class to create interactive applications. The evenodd.java program asks users to input integers and determines whether the number is even or odd by using conditional statements and multiple dialog boxes for user interaction.

Typology: Study Guides, Projects, Research

2019/2020

Uploaded on 10/23/2020

jorge-pons
jorge-pons 🇺🇸

1 document

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
//********************************************************************
// 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);
pf2

Partial preview of the text

Download Java Foundations: EvenOdd.java - Interactive Even or Odd Number Determination and more Study Guides, Projects, Research Java Programming in PDF only on Docsity!

// 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"); }