- Version
- Download 74
- File Size 3.13 KB
- File Count 1
- Create Date May 12, 2016
- Last Updated May 12, 2016
Odd, Even number checker in Java
Odd, Even number checker in Java
A java program that wil determine if the number entered by the user is an odd or even number. The java program has two versions the gui and the console based program. The gui uses swing library and the console uses scanner class.
Happy programming!
Source code:
import javax.swing.*;
class OddEvenCheckerGUI {
public static void main(String[] args) {
String input1;
double num=0, remainder=0;
String cont="n";
do
{
input1 = JOptionPane.showInputDialog(null,"enter a number: ");
num=Double.parseDouble(input1);
remainder=num % 2;
if (remainder ==0){
JOptionPane.showMessageDialog(null, num + " is even number");
}
else{
JOptionPane.showMessageDialog(null, num + " is odd number");
}
cont = JOptionPane.showInputDialog(null,"Continue? y or n ");
}while (cont.matches("y"));
JOptionPane.showMessageDialog(null,"Program Closing");
}
}