//Qus.#2:- check User Enter Number is Even Or Odd?
Solution:-
import java.util.Scanner;
public class Even_Or_Odd {
public static void main(String[] args) {
Scanner sc= new Scanner(System.in);
System.out.println("Enter the number");
int n =sc.nextInt();
if(n%2==0)
{
System.out.println(n+" User Enter Number Is Even");
}
else
{
System.out.println(n+" User Enter Number Is Odd");
}
}
}
🤖Explanation: let's suppose User Entered Number is (n=22)
👉 n=n%2 (Always Gives Reminder)
👉 n=22%2
👉 reminder = 0
Let's Check the condition (n%2==0)
👉 22%2=0
👉 0=0 ( Condition Satisfied that's why this number is Even)
🤙Note:- If we get 1 Reminder then the number is Odd
If we get 0 Reminder then the number is Even
🤦♂️Try Your Self Buddy, If you Get any Error just Comment Below, Definitely, I will try to Solve Your Problem.
0 Comments