Re: Newbie Question

From: Andrew Hobbs (andrewh1_NoSpam__at_iinet.net.au)
Date: 03/23/04

  • Next message: Witold: "list exercise help"
    Date: Tue, 23 Mar 2004 22:11:44 +0800
    
    

    "George" <replytogroup@group.com> wrote in message
    news:1080046317.4840.0@eunomia.uk.clara.net...
    > Hi
    > I trying to initialize an Array with int's and want to print the output as
    > tha Array is filled but I'm getting the two errors below. Could someone
    > please point a lost sheep in the right direction.
    >
    > public class SomeClassTest{
    >
    > public static void main(String[] args) {
    > int [] v;
    > v = new int[10];
    > for (int i = 0; i< v.length; i++);
    > v[i] = i; // error 300 variable i
    > not found in class SomeClassTest

    Your problem is simply that the semicolon after the for() loop limits the
    scope of 'i' which is what the error messages are telling you.
    Assuming you want to print out each value in the array, then delete the
    semicolon and replace with a beginning brace. Then add an ending brace
    after the System.out.println() line. Both statements will then be within
    the scope of 'i'.

    Cheers

    Andrew

    > System.out.println("" + v[i] ); // error 300 variable i not found
    in
    > class SomeClassTest
    >
    >
    > }
    > }
    >
    > TIA
    >
    > George
    >
    >
    >


  • Next message: Witold: "list exercise help"