Good Afternoon all ...
Ive beeen trying this question out for 2 days now but no improvment i might be losing it or something ... can someone help
1- Create the class Even. It should contain two methods:
isEven: The method should take an integer argument and return true if the integer in even and false otherwise. The method should use the reminder operator to determine if the integer is even or not.
The main method should ask the user to input a number and it will call the isEven method to check if it is even or not. If the number is even the maid method will display "YOU ENTERED AN EVEN NUMBER" If the number is odd the mmain method should continue to ask the user to input numbers until he enters "0".
This is what i did
Code:import javax.swing.JOptionPane; class Even { public static void main (String args[]) { String Num1; int number1, num; Num1= JOptionPane.showInputDialog("Enter a number: "); number1 = Integer.parseInt(Num1); isEven(num); System.exit( 0 ); } static void isEven(int a) { if ( a % 2 == 1) { JOptionPane.showMessageDialog(null, "You entered an even number " + a); } else if ( a % 2 == 0) { JOptionPane.showMessageDialog(null, "You entered an odd number " + a); } }//isEven() }//end main
Please tell me if am on the wrong track!!


Reply With Quote

Bookmarks