Check A Number is Even or Odd in Java - CodexRitik

Check A Number is Even or Odd:

Here We will check the number input by user is Even or Odd !
  • Input
Number = 2
Number = 5
  • Output
Number is Even
Number is Odd

  • Code:
import java.util.Scanner;
public class EvenOdd {
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int num;
        System.out.println("Enter the Number :");
        num = scan.nextInt();
        if(num % 2 == 0){
            System.out.println("Number is Even");
        }
        else{
            System.out.println("Number is Odd");
        }
    }
}


  • Explanation:
First we will input any Number then we check that it is divisible by 2 or Not.


Click On Image For Program View
                                                 


🙏THANKS FOR VISIT🙏
Check A Number is Even or Odd in Java - CodexRitik Check A Number is Even or Odd in Java - CodexRitik Reviewed by CodexRitik on July 29, 2020 Rating: 5

No comments:

Powered by Blogger.