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 Respostas
+ 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