Computer Science, asked by priyank88, 6 months ago

Using ternary operator write a simple program to check eligibility of voting

Answers

Answered by janalakshmanarao
2

Answer:

// Java Ternary Operator Example

package JavaOperators;

import java.util.Scanner;

public class TernaryOperator {

private static Scanner sc;

public static void main(String[] args) {

 int age;

 sc = new Scanner(System.in);

 System.out.println(" Please Enter Your Age: ");

 age = sc.nextInt();

 

 String Message = (age >= 18)? " You are eligible to Vote " :  

          " You are Not eligible to Vote ";

 System.out.println(Message);

 

 /** REPLACE THE ABOVE CODE WITH FOLLOWING CODE

  *   System.out.println((age >= 18)?  

  *  " You are eligible to Vote":

                *       "You are Not eligible to Vote");

  */    

}

}

Answered by Anonymous
15

Answer:

The Java Ternary Operator also called a Conditional Operator. The Ternary Operator or Conditional operator in Java programming mostly used in the decision-making process.

Similar questions