Java programming examples with explanation pdf

By John

This is a Java Program to Check if a Given Integer is Odd or Even.
Enter any integer number as an input. Now we check its remainder with modulo operator by two. If remainder is zero the given number is even. If remainder is 1 then the given number is odd. Hence we show output according to the remainder

Here is the source code of the Java Program to Check if a Given Integer is Odd or Even. The Java program is successfully compiled and run on a Windows system. The program output is also shown below.

import java.util.Scanner;
public class Odd_Even
{
public static void main(String[] args)
{
int n;
Scanner s = new Scanner(System.in);
System.out.print(“Enter the number you want to check:”);
n = s.nextInt();
if(n % 2 == 0)
{
System.out.println(“The given number “+n+” is Even “);
}
else
{
System.out.println(“The given number “+n+” is Odd “);
}
}
}
Output:

$ javac Odd_Even.java
$ java Odd_Even

Enter the number you want to check:15
The given number 15 is Odd