Tag: java number programs

  • Java Program to Check whether the Number is Odd or Even

    Here, you will learn to check the number taken from the user as an input using a scanner is Odd or Even. After checking display the result accordingly.

    The concept of checking the number using the Modulus operator. First, calculate the number by modulus by 2, and if the Number mod 2 is equal to 0 then it is an even number else not.

    Flowchart for odd or even number

    Odd_Even_flowchart

    Java Program to Check whether the Number is Odd or Even

     //check the number for odd and even
      
     import java.util.Scanner;
     
     public class CheckEvenOdd 
     {
        public static void main(String[] args) 
        {
            Scanner sc = new Scanner(System.in);
            
            System.out.print("Enter an integer: ");
            int num = sc.nextInt();
            
            if(num % 2 == 0)
                System.out.println(num + " is even");
            else
                System.out.println(num + " is odd");
        }
     }

    Output:

    Enter an integer: 43
    43 is odd