import java.io.*;
public class getLowestValue {
public static void main(String[]args) throws Exception {
DataInputStream input=new DataInputStream(System.in);
System.out.println("Get lowest value ");
int a[]=new int[10];
int x =0, i=0, j=0, tmp=0;
// display and get inputs [5]
for (x=0;x<5;x++){
System.out.print(x+" Enter a number: ");
a[x] = Integer.parseInt(input.readLine());
}
// sorting
for (x=0;x<5;x++){ // loop for 5 times
i = x; // store value of x to i
for (j=x+1;j<5;j++){
if (a[j] < a[i])
i =j;
}
tmp = a[x];
a[x]=a[i];
a[i]=tmp;
}
x=0;
System.out.println(a[x]+ " is the lowest!");
}
}
THIS IS THE PROBLEM:
write a program using one-dimensional array that determines the lowest value among the five input values typed from the keyboard and print the difference of each, value from the lowest.
Like if the user inputs: 56421
It will display:
4
5
3
1
My problem is: I was able to get the lowest number on all the user inputs but the thing is, i scrambled the array in the processed. I arranged it into lowest to highest. My question would be how would i be able to get the lowest value on the inputs without disarranging the original sequence of inputs?