i have this code that is not working but I do not know what it is.
here is the code;
// Create space for stock objects.
Share[] stock = new Share[20];
for(int x = 0; x<stock.length; x++)
{
stock[x].price = x;
System.out.println(stock[x].price);
}
class stock(){
public int price;
public stock(){
this.price = 30;
}
}
It should output 20 different numbers, but nothing outputs.
Ryan Stewart - 08 Dec 2004 03:05 GMT
>i have this code that is not working but I do not know what it is.
>
[quoted text clipped - 5 lines]
> for(int x = 0; x<stock.length; x++)
> {
stock[x] = new Share();
> stock[x].price = x;
> System.out.println(stock[x].price);
[quoted text clipped - 11 lines]
>
> It should output 20 different numbers, but nothing outputs.
It shouldn't output anything. It shouldn't even compile. Try posting real
code. See
http://www.physci.org/codes/sscce.jsp
Rob - 08 Dec 2004 03:09 GMT
> i have this code that is not working but I do not know what it is.
>
[quoted text clipped - 20 lines]
>
> It should output 20 different numbers, but nothing outputs.
I think your stock class needs to be a Share class.
Then, you'd go
for(int i = 0; i < stock.length; i++)
{
stock[x] = new Share();
stock[x].price = x;
}
-rob
Rob - 08 Dec 2004 06:18 GMT
>> i have this code that is not working but I do not know what it is.
>>
[quoted text clipped - 32 lines]
>
> -rob
Oh, and by 'x' I meant 'i'
-rob