KnowledgeBoat Logo

Computer Applications

Write a program to input three numbers and print the largest of the three numbers.

Java

Java Conditional Stmts

7 Likes

Answer

import java.util.Scanner;

public class KboatLargestNumber
{
    public static void main(String args[]) {
        Scanner in = new Scanner(System.in);
        System.out.print("Enter first number: ");
        int a = in.nextInt();
        System.out.print("Enter second number: ");
        int b = in.nextInt();
        System.out.print("Enter third number: ");
        int c = in.nextInt();
        
        System.out.print("Largest number: ");
        if (a > b && a > c)
            System.out.println(a);
        else if (b > a && b > c)
            System.out.println(b);
        else
            System.out.println(c);
    }
}

Variable Description Table

Program Explanation

Output

BlueJ output of Write a program to input three numbers and print the largest of the three numbers.

Answered By

3 Likes


Related Questions