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"

    Relevant Pages

    • Re: Newbie Question
      ... >> tha Array is filled but I'm getting the two errors below. ... >> not found in class SomeClassTest ... available after your forloop has completed. ... metasens AntiSpam @iinet dot net dot au ...
      (comp.lang.java.help)
    • Re: Is it possible to use the value of the PROGRAM ID within the source code?
      ... Until the universal availability of scope terminators there were ... But 'reusability' is not a unique feature of OO design. ... remain and some are now garbage. ... A tree can be made faster by increasing its width; an array ...
      (comp.lang.cobol)
    • Re: Packages and returning errors
      ... > array intact. ... sub is_a_instance_method { ... my $class = shift; ... You need to fix the scope of $error by moving its declaration outside ...
      (comp.lang.perl.misc)
    • Re: Solar power questions....
      ... Set the array up facing the sun, but put a sheet of cardboard ... And good DMMs have two fuses -- one for low ... I could use an inexpensive scope. ...
      (rec.crafts.metalworking)
    • Re: Solar power questions....
      ... Set the array up facing the sun, but put a sheet of cardboard ... And good DMMs have two fuses -- one for low ... I could use an inexpensive scope. ... They are inside the power supply module, and are six 'C' size NiCads. ...
      (rec.crafts.metalworking)