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 < values.size(); i++) { // auto boxing and unboxing values.set(i, values.get(i) + 1); } } private void printList(ArrayList list) { for(int i = 0; i < list.size(); i++) { println(list.get(i)); } } /* Private instance variable */ ArrayList<Integer> values = new ArrayList<Integer>(); }...
View Full Document

This note was uploaded on 02/18/2010 for the course CS 106A taught by Professor Sahami,m during the Fall '08 term at Stanford.

Ask a homework question - tutors are online