Programming Challenge
Write a program that accepts 3 integers. Then use operators to determine:
1. the largest number
2. whether all numbers are positive
3. whether at least one number is negative
Example
Input:
5, -2, 10
Output:
Largest number among 5, -2 and 10 is 10
All positive = false
at least one negative = true
public class Largestnum{
public static void main(String [] args){
int fnum = 5;
int snum = -2;
int tnum = 10;
int number =
((snum < fnum) && (tnum < fnum)) ? fnum :
((fnum < snum) && (tnum < snum)) ? snum : tnum ;
[Link]("____________________");
[Link]();
[Link]("Largest number among " + fnum + "," + snum + " and " + tnum + " is
" + number );
boolean pos = (( fnum >0 ) && (snum >0 ) && (tnum >0));
[Link]("All positive = " + pos);
boolean neg = (( fnum <0 ) || (snum <0 ) || (tnum <0));
[Link]("At least one negative = " + neg);
[Link]("____________________");
}
}