In this page you can learn to write a code to check the number is even or odd. The steps are given below
- First create the java file with the main class.
- Then import the scanner function.
- Use the variable number and declare in the integer.
- Then use the if else statement to check the number.
- In the if statement use(number%2==0) . When the condition is true then the result will be print as even.
- When the if statement is false the it will print as odd.
JAVA PROGRAMMING TO CHECK ODD OR EVEN
import java.util.Scanner;
class Even{
public static void main(String args[]){
int number;
Scanner sc=new Scanner(System.in);
number=sc.nextInt();
if(number%2==0){
System.out.println("The entered number is even");
}
else{
System.out.println("The entered number is odd");
}
}
}
INPUT
5
OUTPUT
odd
إرسال تعليق