How do I choose 2 highest numbers from 3 numbers given by a user in Java | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How do I choose 2 highest numbers from 3 numbers given by a user in Java

8th Oct 2020, 10:54 AM
Andiswa
5 Answers
+ 2
Finding 2 greatest numbers from 3 is equivalent to finding the smallest number out of 3 and get the rest. So you can find the smallest number and the rest will be the greater 2 numbers.
8th Oct 2020, 11:03 AM
你知道規則,我也是
你知道規則,我也是 - avatar
+ 2
int num1; int num2; int num3; int bigNum=Math.max(Math.max(num1,num2),num3); System.out.println(bigNum);
8th Oct 2020, 5:28 PM
0_O-[Mägár_Sám_Äkà_Nüllpøïntêr_Èxëcéptïön]~~
0_O-[Mägár_Sám_Äkà_Nüllpøïntêr_Èxëcéptïön]~~ - avatar
0
I tried using the formulae, but it requires me to show the two maximum numbers
8th Oct 2020, 11:06 AM
Andiswa
0
You can assign them to variables while comparing. Saying you have int a, b, c to compare. You can declare 2 variables to hold the greater 2 numbers. Like you can apply your code this. int max1; if(a<b) { max1 = b; } else { max1 = a; }
8th Oct 2020, 11:23 AM
你知道規則,我也是
你知道規則,我也是 - avatar
0
Thank you
8th Oct 2020, 12:43 PM
Andiswa