Using ternary operator write a simple program to check eligibility of voting
Answers
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");
*/
}
}
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.