so im trying to create a program in java which will create a 10 by 10 matrix, with each element displaying either a 1 or a 0 randomly. Here is what i have so far:
You can't have arbitrary statements inside a class definition. Perhaps you want to put it in the constructor?
class Random {
public Random() {
GridLayout setLayout = new GridLayout(10, 10);
for (int i = 0; i < 10; i++)
{
int number = (int) (Math.random() * 2);
String str = Integer.toString(number);
setLayout.add(new JLabel(str, JLabel.CENTER));
}
}
}
Or, you could just create another method and place it in there.