0

How does one get the lowest number of multiple numbers

16th May 2017, 8:31 AM
Eugene Msipa
Eugene Msipa - avatar
2 ответов
+ 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.
16th May 2017, 8:54 AM
Jmse
+ 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]);
16th May 2017, 9:59 AM
LordHill
LordHill - avatar