Check If Number even or odd- Java Program | TOP 100 CODES |

Опубликовано: 26 Февраль 2025
на канале: SheCodes
186
21

The basic Java Program to check whether the given Number is Even or Odd.
We use if-else Conditional Statement .
Below is the code :-
import java.util.Scanner;
public class prob2{
public static void main(String[] args){
//Using Scanner class to take input from user
Scanner scan = new Scanner(System.in);
System.out.println("Enter num:- ");
int num = scan.nextInt();//we use nextInt() to tak integer as an input

//using a if else statement to check for even and odd
if(num%2==0){
System.out.println("The given Number is Even.");
}else{
System.out.println("The given Number is odd.");
}
}
}