0% found this document useful (0 votes)
3 views1 page

Largest Number and Positivity Check

Uploaded by

hajinmaru4
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views1 page

Largest Number and Positivity Check

Uploaded by

hajinmaru4
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

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]("____________________");
}
}

You might also like