Computer Applications

Write a program to input three numbers and check whether they are equal or not. If they are unequal numbers then display the greatest among them otherwise, display the message 'All the numbers are equal'.

Sample Input: 34, 87, 61
Sample Output: Greatest number: 87
Sample Input: 81, 81, 81
Sample Output: All the numbers are equal.

Java

Java Conditional Stmts

156 Likes

Answer

import java.util.Scanner;

public class Kboat3Numbers
{
    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();
        
        if (a == b && b == c) {
            System.out.println("All the numbers are equal");
        }
        else {
            int g = a;
            
            if (b > g)
                g = b;
                
            if (c > g)
                g = c;
                
            System.out.println("Greatest number: " + g);
        }
    }
}

Variable Description Table

Program Explanation

Output

Answered By

55 Likes


Related Questions