0
How do I choose 2 highest numbers from 3 numbers given by a user in Java
5 ответов
+ 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.
+ 2
int num1;
int num2;
int num3;
int bigNum=Math.max(Math.max(num1,num2),num3);
System.out.println(bigNum);
0
I tried using the formulae, but it requires me to show the two maximum numbers
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;
}
0
Thank you