In: Computer Science
How to write a java application that reads an integer, then determines and display whether it's odd or even. Use the remainder operator.
import javax.swing.JOptionPane;
public class BasicGUI {
public static void main(String[] args) {
// TODO Auto-generated method stub
//Showing the Welcome message in Dialog Box
JOptionPane.showMessageDialog(null, "Welcome");
//Asking the User to input a number
String input = JOptionPane.showInputDialog("Enter a Number");
//Converting the string version of number to Integer version
int num = Integer.parseInt(input);
//Showing the appropriate message for even or odd
if(num%2==0){
JOptionPane.showMessageDialog(null, num+" is even number");
}
else{
JOptionPane.showMessageDialog(null, num+" is odd number");
}
}
}
Output