I have to write a program that takes the smallest number from a list of numbers and puts it on the first position.
public static void minToFront (ArrayList<Integer> minInteger)
{
int result = 0;
int min = minInteger.get(0);
for (int i = 0; i < minInteger.size(); i++)
{
if (minInteger.get(i)< min)
{
min = minInteger.get(i);
result = min;
}
}
minInteger.add(0, minInteger.remove(result));
I wrote the first part of the code, but now i have to write a program that test the above method. And i don't know how to call the method and set the parameters. I wrote this but is uselles.
import java.util.ArrayList;
public class testVowelsandIntegers
{
public static void main (String [] args)
{
VowelsandIntegers myList = new VowelsandIntegers();
ArrayList<Integer> list = new ArrayList<Integer>();
list.add(19);
list.add(6);
list.add(15);
list.add(3);
myList.minToFront(list);
System.out.printf("Display numbers\n", myList.minInteger);
}
}