English

Write a program to input three numbers (positive or negative). If they are unequal then display the greatest number otherwise, display they are equal. - Computer Applications

Advertisements
Advertisements

Question

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.

Answer in Brief

Solution

import java.util.*;
public class Q1 
{public static void main(String args[]) 
{Scanner in = new Scanner(System.in); 
int a, b, c, max;
System.out.printIn("Enter the three numbers"); 
System.out.println("Enter positive/negative numbers only"); 
a = in.nextInt(); 
b = in.nextInt(); 
c = in.nextInt(); 
if (a == b && b == c) 
System.out.printIn("The numbers are equal"); 
else 
{max = (a > b && a > c) ? a : (b > c ? b : c); 
System.out.printIn("The numbers are unequal, the greatest number is "+ max); 

if (a < 0 && b < 0 && c < 0) 
System.out.printin("All negative"); 
else if (a > 0 && b > 0 && c > 0) 
System.out.println("All positive"); 
else 
System.out.printIn("The combination of positive and negative numbers"); 
}
}}
shaalaa.com
  Is there an error in this question or solution?
Chapter 1.08: Conditional Statements in Java - EXERCISES [Page 100]

APPEARS IN

Avichal Computer Applications [English] Class 10 ICSE
Chapter 1.08 Conditional Statements in Java
EXERCISES | Q VI. 1. | Page 100
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×