nature-of-code / noc-examples-processing

Repository for example code from The Nature of Code book
MIT License
2.55k stars 953 forks source link

Probability #109

Open LucasColas opened 4 years ago

LucasColas commented 4 years ago

Hello, I'm trying to learn processing and I'm working on this exercise :

int [] stuff = new int[5]

stuff[0] = 1; stuff[1] = 1; stuff[2] = 2; stuff[3] = 3; stuff[4] = 3;

int index = int(random(stuff.length));

But I have an error : "Syntax error, maybe a missing ] character?"

Could you help me ?

MagusX commented 4 years ago

You miss the ";" at line 1 or maybe instead of int [] you should write int[]

MonkeyDLy commented 4 years ago

You missed a " ; " perhaps is that

LucasColas commented 4 years ago

Thanks for the answer ! Now my code is : int[] stuff = new int[5];

stuff[0] = 1; stuff[1] = 1; stuff[2] = 2; stuff[3] = 3; stuff[4] = 3;

int index = int(random(stuff.length));

And I have another error : "Missing right curly bracket "}" " and "unexpected token"...

LucasColas commented 4 years ago

"unexpected token: [" exactly.

LucasColas commented 4 years ago

Ok, I had to add {} : int[] stuff = new int[5]; { stuff [0] = 1; stuff [1] = 1; stuff [2] = 2; stuff [3] = 3; stuff [4] = 3;

int index = int(random(stuff.length));

}

but why ?