/** * Esimerkki dynaamisesta taulukosta * @author Vesa Lappalainen * @version 1.0, 02.03.2002 */ public class Taulukko { public class TaulukkoTaysiException extends Exception { TaulukkoTaysiException(String viesti) { super(viesti); } } private int alkiot[]; private int lkm; public Taulukko() { alkiot = new int[10]; } public Taulukko(int koko) { alkiot = new int[koko]; } public void lisaa(int i) throws TaulukkoTaysiException { if ( lkm >= alkiot.length ) throw new TaulukkoTaysiException("Tila loppu"); alkiot[lkm++] = i; } public String toString() { StringBuffer s = new StringBuffer(""); for (int i=0; i