SimpleArrayListExample

SimpleArrayListExample - printArrayList(list); } private...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
/* * SimpleArrayListExample.java * --------------------------- * This program shows an example of using an ArrayList. */ import acm.program.*; import java.util.*; public class SimpleArrayListExample extends ConsoleProgram { public void run() { setFont("Courier New-24-Bold"); ArrayList<Integer> list = new ArrayList<Integer>(); readList(list); printArrayList(list); readList(list);
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: printArrayList(list); } private void readList(ArrayList&lt;Integer&gt; list) { while (true) { Integer item = readInt(&quot;? &quot;); if (item == 0) break; list.add(item); } } private void printArrayList(ArrayList list) { println(&quot;List contains &quot; + list.size() + &quot; elements&quot;); for(int i = 0; i &lt; list.size(); i++) { println(list.get(i)); } } }...
View Full Document

Ask a homework question - tutors are online