KnowledgeBoat Logo

Computer Applications

Write a program to input three numbers (positive or negative). If they are unequal then display the greatest number otherwise, display they are equal. The program also displays whether the numbers entered by the user are 'All positive', 'All negative' or 'Mixed numbers'.
Sample Input: 56, -15, 12
Sample Output:
The greatest number is 56
Entered numbers are mixed numbers.

Java

Java Conditional Stmts

131 Likes

Answer

import java.util.Scanner;

public class KboatNumberAnalysis
{
    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();
        
        int greatestNumber = a;
        
        if ((a == b) && (b == c)) {
            System.out.println("Entered numbers are equal.");
        }
        else {
            
            if (b > greatestNumber) {
                greatestNumber = b;
            }
            
            if (c > greatestNumber) {
                greatestNumber = c;
            }
            
            System.out.println("The greatest number is " + greatestNumber);
            
            if ((a >= 0) && (b >= 0) && (c >= 0)) {
                System.out.println("Entered numbers are all positive numbers.");
            }
            else if((a < 0) && (b < 0) && (c < 0)) {
                System.out.println("Entered numbers are all negative numbers.");
            }
            else {
                System.out.println("Entered numbers are mixed numbers.");
            }
        }
    }
}

Variable Description Table

Program Explanation

Output

BlueJ output of Write a program to input three numbers (positive or negative). If they are unequal then display the greatest number otherwise, display they are equal. The program also displays whether the numbers entered by the user are 'All positive', 'All negative' or 'Mixed numbers'. Sample Input: 56, -15, 12 Sample Output: The greatest number is 56 Entered numbers are mixed numbers.

Answered By

51 Likes


Related Questions