rewrite the following using if-else System.out.print(x%2==0?"even":"odd");
Answers
Answered by
1
Answer:
Explanation:
if(x%2==0)
{ System.out.println("even");
}
else
{System.out.println("odd");
}
hope it is helpful
please mark as brainliest
Answered by
1
Rewrite the following using if-else System.out.print(x%2==0?"even":"odd");
Explanation:
Java Program to check number is Even or Odd
import java.util.Scanner;
public class Main
{
public static void main(String args[])
{
int x;
System.out.println("Enter a number to check if it is odd or even: ");
Scanner in = new Scanner(System.in);
x = in.nextInt();
if (x % 2 == 0) ///If number is divisible by 2 then it's an even number
System.out.println("The number is even.");
else
System.out.println("The number is odd.");
}
}
Output
Enter a number to check if it is odd or even:
6
The number is even.
Similar questions