> brett, i don't understand what you're trying to say. i want to replace
> all 'stock[1]' with 'stock[i]']. i need to use the 'i' that i declared
> in the 'for' loop.
>
> how do i reference that 'i'?
>>brett, i don't understand what you're trying to say. i want to replace
>>all 'stock[1]' with 'stock[i]']. i need to use the 'i' that i declared
[quoted text clipped - 12 lines]
>
> http://www.physci.org/codes/sscce.jsp
the compiler error i recieve is: 'variable 'i' not initialized'
here is the code again;
for(int i =1; i<stock.length;i++)
{
System.out.print("Input the price: ");
System.out.flush();
try {
if ((line = stndin.readLine()) != null)
stock[i].price = Double.valueOf(line).intValue();
} catch (IOException e) {
}
System.out.print("Input the quantity: ");
System.out.flush();
try {
if ((line = stndin.readLine()) != null)
stock[i].quantity = Integer.valueOf(line).intValue();
} catch (IOException e) {
}
System.out.println("buy " + stock[i].quantity + " at $" +
stock[i].price + " each.");
}
is it because the 'i' variable is in the try() statement? if so how
would i reference the declared 'i' in the for loop in the try()
statement?
since i delcared 'i' to be 1 in the for() statement, when 'i' goes
through the try() statements, 'i' should be 1, right?
Andrew Thompson - 07 Dec 2004 00:29 GMT
>> http://www.physci.org/codes/sscce.jsp
..
> the compiler error i recieve is: 'variable 'i' not initialized'
...
> here is the code again;
>
> for(int i =1; i<stock.length;i++)
A quiz for you Kenneth. What do the second S and first C
os SSCCE mean? Why are they important?

Signature
Andrew Thompson
http://www.PhySci.org/codes/ Web & IT Help
http://www.PhySci.org/ Open-source software suite
http://www.1point1C.org/ Science & Technology
http://www.LensEscapes.com/ Images that escape the mundane
Kenneth - 07 Dec 2004 20:31 GMT
>>> brett, i don't understand what you're trying to say. i want to
>>> replace all 'stock[1]' with 'stock[i]']. i need to use the 'i' that
[quoted text clipped - 44 lines]
> since i delcared 'i' to be 1 in the for() statement, when 'i' goes
> through the try() statements, 'i' should be 1, right?
for some reason, the error message is gone. now it goes through the
loop once and the second time around it just stops at
"System.out.print("Input the quantity: ");"
any ideas what might be going on?