Computer Science, asked by jagannathds314, 9 months ago

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

Answered by ItzMeSam35
1

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();

}

}

Similar questions