Check User Enter Number is Even or odd Without Using 'if ' Statement.

//Qus:- #4. Write a Java Program Without Using 'if ' Check User Entered Number is Even or odd.

  • Check User Entered Number is Even Or odd without ' If ' Statement?

Solution:-
 import java.util.Scanner;  
 public class Demo {  
      public static void main(String[] args) {  
           Scanner sc = new Scanner(System.in);  
           System.out.println("Enter the number");  
           int n = sc.nextInt();  
           String number=(n%2==0)?"Even":"Odd"; //Using Ternary operator ( ? : )  
           System.out.println(n+" is "+ number);  
      }  
 }  
"Even Odd without using if," "Check User Number is Even or odd" "How to Check User Entered Number is Even or odd" "How to Check Number is Even or odd" "How to Check Even or odd without using if" "How to Check Even or odd in java"
"Even Odd without using if," "Check User Number is Even or odd" "How to Check User Entered Number is Even or odd" "How to Check Number is Even or odd" "How to Check Even or odd without using if" "How to Check Even or odd in java"

🤖Explanation: let's Suppose User Entered Number is (n=21).

Example 1:- Check User Entered number is even or Odd just applying condition (n%2==0)
if the user entered number is divisible by 2 then it's print Even otherwise prints Odd.


👉  21%2= 1(Reminder)
🤙this number is not satisfied with the condition so it's Print Odd.

Example 2:- let's Suppose User Entered Number is (n=20);
let's check the condition:- (n%2==0)


👉  20%2=0 (Reminder)
🤙User entered number is satisfied the Condition so it's print Even

🤦‍♂️Try Your Self Buddy,  If you Get any Error just Comment Below, Definitely, I will try to Solve Your Problem.


Admin Words:- I am always tried to solve this program in a simple way. Which helps you to understand easily?  Hopefully, now you can understand How to check Even Or odd without ' If ' Statement. If you find any error in this program please remind us to comment below of this post. And stay away to learn programs J with Us. and also Read our Next Program.


Recommended: - 







Post a Comment

0 Comments