1 d arrays :: samples and exercises
public static void main (String[] args)
{
int age [] = new int [20]; // array declaration
for (int i = 0 ; i < 19 ; i++) // populate array with a loop
{
System.out.println (age [i] = i + 2);
}
System.out.println (age [9]); // output specific element
} // main method
Input using BufferedReader
public static void main (String[] args) throws IOException
{
BufferedReader obj = new BufferedReader (new InputStreamReader (System.in));
int num [] = new int [9]; // declaration
for (int i = 0 ; i < 9 ; i++) // input the keyboard
{
num [i] = Integer.parseInt(obj.readLine ());
}
for (int i = 0 ; i < 9 ; i++) // output to screen
{
System.out.println (score [i]);
}
} // main method