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
Sanfoundry Global Education & Learning Series - 1000 Java Programs.
advertisement
advertisement
Here’s the list of Best Books in Java Programming, Data Structures and Algorithms.
Related Posts:
- Practice BCA MCQs
- Apply for Computer Science Internship
- Apply for Java Internship
- Practice Information Technology MCQs
- Check Java Books