Write a Java Program to Check Whether a Number is Even or Odd

Java Program to Check Whether a Number is Even or Odd

Welcome to the World of Online Learning:

Hello Friends “This blog helps you to learn Java programming concepts. You can learn Java  language at your own speed and time. One can learn concepts of Java language by practicing various programs given on various pages of this blog. Enjoy the power of Self-learning using the Internet.”

Java Program to Check Whether a Number is Even or Odd
Java Program to Check Whether a Number is Even or Odd

Write a Java Program to Check Whether a Number is Even or Odd

PROGRAM: Java Program to Check Whether a Number is Even or Odd

/* Java Program to Check Whether a Number is Even or Odd */

import java.util.Scanner;

public class EvenOdd {

public static void main(String[] args) {

Scanner reader = new Scanner(System.in);

System.out.print(“Enter a number: “);
int num = reader.nextInt();

if(num % 2 == 0)
System.out.println(num + ” is even”);
else
System.out.println(num + ” is odd”);
}
}

 

Leave a Reply

Your email address will not be published. Required fields are marked *