Write a program in Java to accept a number (using Function argument of main ( ) method) and check whether it is a three digits Even Number or Odd Number using only Nested Ternary Operator. Display the results with proper message
Answers
Answer:
import java.util.Scanner;
public class EvenOdd {
public static void main(String[] args) {
Scanner reader = new Scanner(System.in);
System.out.print("Enter a number: ");
int num = reader.nextInt();
if(num % 2 == 0)
System.out.println(num + " is even");
else
System.out.println(num + " is odd");
}
}
please mark my ans as Brainlist
import java.util.Scanner;
public class TernaryExample {
public static void main(String [] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Please enter a number : ");
int n = sc.nextInt();
if (n <= 999 && n >= 100) {
String s = (n % 2 == 0) ? "Even three digit number" : "Odd three digit number";
System.out.println(s);
}
else {
System.out.println("It is not a three digit number");
}
sc.close();
}
}