I am trying to input an integer thru JOptionPane and have that number become the size of a one dimensional table. The MyDriver main calls the method class MyArray.
i am getting a compile error on my System.out.println because "counter" is unresolved.
Any idea why or what i am doing wrong and whether the scheme will work otherwise?
???
thanx
djb
//START main
import javax.swing.JOptionPane;
import java.text.*;
public class MyDriver
{ public static void main (
String[ ] arg)
{ String firstNumber;
String kVal, fVal, minVal, maxVal, medVal;
int x;
firstNumber = JOptionPane.showInputDialog("Enter an integer number:");
try
{ x = Integer.parseInt( firstNumber ); }
catch ( NumberFormatException nfe)
{ x = 0; }
MyArray my = new MyArray( x );
my.fill();
}//END main
//START method class
public class MyArray
{ private int [ ] a; // int array declaration as private
MyArray ( int x ) { a = new int [ x ]; }
void fill()
{ for (int counter = 0; counter < a.length; counter++)
a[ counter ] = 100 + ( int ) ( Math.random () * 100 );
System.out.println(counter +" " +a[ counter ]); }
}//END method class
[ February 26, 2004: Message edited by: Douglas Braxton ]
[ February 26, 2004: Message edited by: Douglas Braxton ]