ICSE Class 8 Computer Studies Question 7 of 10

Decision Control Structure — Question 8

Back to all questions
8
Question

Question 8

Write a program to print the largest of three numbers.

public class KboatLargestNumber
{
    public static void largestNumber(int a, int b, int c) {
        System.out.println("The three numbers are " 
               + a + ", " + b + ", " + c);
        
        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);
    }
}
Output
BlueJ output of KboatLargestNumber.java
Answer