NumberList

NumberList - // auto boxing of 0 to Integer values.add(0);...

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

View Full Document Right Arrow Icon
import acm.program.*; import java.util.*; public class NumberList extends ConsoleProgram { public void run() { setFont("Times New Roman-24"); int numValues = readInt("Number of values: "); initValues(numValues); println("Values before increment"); printList(values); incrementValues(); println("Values after increment"); printList(values); } private void initValues(int numValues) { for(int i = 0; i < numValues; i++) {
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: // auto boxing of 0 to Integer values.add(0); } } private void incrementValues() { for(int i = 0; i &lt; values.size(); i++) { // auto boxing and unboxing values.set(i, values.get(i) + 1); } } private void printList(ArrayList list) { for(int i = 0; i &lt; list.size(); i++) { println(list.get(i)); } } /* Private instance variable */ ArrayList&lt;Integer&gt; values = new ArrayList&lt;Integer&gt;(); }...
View Full Document

Ask a homework question - tutors are online