In this article I would like to share with you a sample program that will ask the user a number and then our program will check and determine if the given number is an even or odd number using object oriented programming approach. The code is very simple and easy to understand. Thank you.
My email address are the following jakerpomperada@gmail.com and jakerpomperada@yahoo.com.
My mobile number here in the Philippines is 09173084360.
Sample Program Output
Program Listing
odd_even.java
package demo;
import java.util.Scanner;
class odd_even_value {
int val_1=0;
}
class odd_even {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
odd_even_value a = new odd_even_value();
System.out.println();
System.out.println("ODD AND EVEN NUMBER CHECKER IN JAVA OOP");
System.out.println();
System.out.print("Enter a Number : ");
a.val_1 = input.nextInt();
if ( a.val_1 % 2 == 0 ) {
System.out.println();
System.out.println("You entered an EVEN number.");
}
else {
System.out.println();
System.out.println("You entered an ODD number.");
}
input.close();
}
}