Hi, I've been trying to sort a list in ascending order for a problem in class, but my for loop isn't working.
import java.util.*;
public class AscendingOrder
{
public static void main(String[]args)
{
int min;
Scanner input=new Scanner(System.in);
int[]list;
list=new int[10];
int[]list1;
list1=new int[10];
System.out.print("Enter 10 integers: ");
for (int i=0; i<10; i++)
list[i]=input.nextInt();
min=1000000;
for (int j=0; j<10; j++)
for (int i=j; i<10; i++)
if (list[i]<min)
list1[j]=(min=list[i]);
for (int j=0; j<10; j++)
System.out.println(list1[j] + "");
}
}
Probably most of you know this, but I will explain the code above and my ideas in more detail in case it helps.
It is supposed to ask for a list of 10 integers which it will input into list[]. It will also create a new list to put in the sorted numbers later, which is list1[]. Then setting the min at a random high value (1000000), the for loops go through list[] and find the min, then input that into list1[] and repeat until it is filled. However, when I do this, I just get the same number (the min) repeated within list1[]. Is this because I need to remove that number from later on in the list, otherwise it keeps being treated as the min? And if so, could you give me some hints to do so?