0
How does one get the lowest number of multiple numbers
2 Answers
+ 2
Hi @Eugene Msipa, can you provide more information about how the numbers are provided? For example, they are provided inside a List, an Array...
Either way, you need an auxiliary variable to store the current lowest value:
1. Store first number (any of them) in the auxiliary variable.
2. Compare aux var with other number and if it is lower than aux, asign new number to aux variable.
3. Repeat stem 2 until you compare all numbers.
Remaining number in aux variable is your lowest number.
+ 1
Many ways to do this. An easy way is
//Add your numbers to an array
int[] numbers={2,3,8,1};
//Sort them lowest to highest
java.util.Arrays.sort(numbers);
//Then first index is the smallest number
System.out.println(numbers[0]);