Java Program To Demonstrate Ternary Operator

Write Java program to demonstrate the use of the ternary operator

// WAP to demonstrate the use of ternary operator

import java.util.Scanner;
public class TernaryOperator
    public static void main(String []args)
        int age;
        Scanner sc = new Scanner(;

        System.out.println("Enter your age :-->");
        age = sc.nextInt();

        boolean b =(age >= 18) ? true:false;

            System.out.println("You are eligible to vote");
            System.out.println("You are not eligible to vote");

        sc.close(); // to prevent memory leakage



<< Previous | Next >>

Leave a Reply

Your email address will not be published.