Answers for "chec even using ternary operator java"

1

Even odd program in java using ternary operator

import java.util.Scanner;
public class EvenOddTernary
{
   public static void main(String[] args) 
   {
      Scanner sc = new Scanner(System.in);
      System.out.println("Please enter a number : ");
      int number = sc.nextInt();
      // java odd or even
      String strOutput = (number % 2 == 0) ? "even" : "odd";   
      System.out.println(number + " is " + strInput);
      sc.close();
   }
}
Posted by: Guest on February-09-2021

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language