ADVERTISEMENT
ADVERTISEMENT

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 »


ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions


ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.