Write a java program to check a number is even or odd.
Answers
★ Java Program to check for even or odd number.
import java.util.Scanner;
class EveOdd
{
public static void main(String args[ ])
{
int num;
System.out.println("Enter an Integer Number");
Scanner input = new Scanner(System.in);
num = input.nextInt();
if
( num % 2 == 0 )
System.out.println("The Number is EVEN");
else
System.out.println("The Number is ODD");
}
}
▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬
★ Refer attachment for the Output.
★ Input number in the above output is 10.
/*
Project Type: Brainly Answer
Date Created: 10-02-2021
Date Edited Last Time: ---NIL---
Question Link: https://brainly.in/question/34926419
Question: Write a java program to check a number is even or odd.
Program Created By: atrs7391
Programming Language: Java
Language version (When program created or last edited): jdk-15.0.2
*/
package Brainly_Answers;
import java.util.Scanner;
public class To_Check_Number_Is_Odd_Or_Even {
public static void main(String[] args) {
Scanner sc = new Scanner (System.in);
System.out.println("Enter a number: ");
long n = sc.nextLong();
// taking input from user and storing it into variable n
if (n%2==0)
// checking if the number is even
{
System.out.println("Given Number is Even Number ");
// if the number is even, then printing the message, it's even
}
else
// if the number is not even, then it's obvious that number is odd
{
System.out.println("Given Number is Odd Number ");
// now if number is odd then printing, number is odd
}
}
}