Q:

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

belongs to collection: Java Most Popular & Searched Programs

0

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

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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

 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Java program to print multiplication table of give... >>
<< Java program to convert distance from miles to kil...