Computer Science, asked by us896592, 3 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 singhyogendra559
3

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

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