even odd program in java using ternary operator

Solutions on MaxInterview for even odd program in java using ternary operator by the best coders in the world

showing results for - "even odd program in java using ternary operator"
Ailsa
31 Jan 2020
1import java.util.Scanner;
2public class EvenOddTernary
3{
4   public static void main(String[] args) 
5   {
6      Scanner sc = new Scanner(System.in);
7      System.out.println("Please enter a number : ");
8      int number = sc.nextInt();
9      // java odd or even
10      String strOutput = (number % 2 == 0) ? "even" : "odd";   
11      System.out.println(number + " is " + strInput);
12      sc.close();
13   }
14}