The compiler reports no errors, yet the output is completely blank and I'm stumped. I've tried it with a regular for loop and a for-each (both shown below) and neither outputs anything. Can anyone see what I'm missing?
import java.util.ArrayList;
public class ArrayListTest
{
public static void main(String[] args)
{
ArrayList<Double> someArray = new ArrayList<Double>(20);
for (int i = 0; i < someArray.size(); i++)
someArray.add(i + 0.5);
for (int i = 0; i < someArray.size(); i++)
System.out.print(someArray.get(i) + ", "); // prints out 0.5, 1.5, 2.5 ... 20.5
System.out.println(); // to add a carriage return and blank line
for (Double x : someArray)
System.out.print(x + ", "); // prints out 0.5, 1.5, 2.5 ... 20.5
}
}


Sign In
Create Account


Back to top









