Java program to find out largest integer number among three using conditional operator

This java program will read three integer numbers and find largest number among them using conditional/ternary operator, this program is an example to find the largest of three numbers conditional operator.

package com.includehelp;

import java.util.Scanner;

/**
 * program to find out largest integer number among three using conditional operator
 * @author includehelp
 */
public class LargestNumber {
    
    /**
     * Method to find largest number using conditional operator
     * @param a
     * @param b
     * @param c
     * @return 
     */
    static int getLargest(int a,int b,int c){
        int largeest = (a>b?(a>c?a:c):(b>c?b:c));
        return largeest;
    }
    
    public static void main(String[] args) {
         Scanner sc  =   new Scanner(System.in);
        System.out.print("Enter First Number  : ");
        int a =   sc.nextInt();
        System.out.print("Enter Second Number  : ");
        int b =   sc.nextInt();
        System.out.print("Enter Third Number  : ");
        int c =   sc.nextInt();
        
        System.out.println("Largest Number : "+getLargest(a, b, c));
        
    }
}

Output

Enter First Number  : 45
Enter Second Number  : 90
Enter Third Number  : 23
Largest Number : 90

Java Most Popular & Searched Programs »





Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.