Haw to sing minimum? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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); } }

25th Jan 2019, 5:07 PM
Abdi Shakuur Hamud Ali
Abdi Shakuur Hamud Ali - avatar
2 Answers
+ 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); } }
25th Jan 2019, 5:17 PM
Lambda_Driver
Lambda_Driver - avatar
+ 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.
25th Jan 2019, 5:18 PM
Lambda_Driver
Lambda_Driver - avatar