0
Haw to sing minimum?
public class Main { public static void main(String[] args) { int a = 2000; int b = 1000; int min=1000; if (a < b) { // TODO: assign min System.out.println("minimum is a"); } else { // TODO: assign min } System.out.println("The minimum of a and b is: " + min); } }
2 Antworten
+ 5
You could do it like this:
public class Main
{
public static void main(String[] args)
{
int a = 2000;
int b = 1000;
int min=0;
if (a < b)
{
min = a;
}
else
{
min = b;
}
System.out.println("The minimum of a and b is: " + min);
}
}
+ 5
Instead of using the if-else statement, you could use the built-in min function to get the lesser number:
min = Math.min(a,b);
It will give you the same result.