I am learning Java through self-reading. Right now I am doing a exercise. I am trying to create variable size of 2D-array then assign random number from 10 to 100 and put it into each array.
the problem I am encountering is don't know how to get each 2D-array out and put it into a string then show it through dialog after finish creating variable object.
here is my code.
import java.security.SecureRandom;
import javax.swing.JOptionPane;
import java.util.ArrayList;
public class Random {
public int randomNum;
public String ID;
public Random(String ID, int initialValue) {
SecureRandom randomNumbers = new SecureRandom();
this.ID = ID;
this.randomNum = initialValue;
int randomValue = randomNumbers.nextInt(99) + 1;
randomNum = randomValue;
}
public int getRandomNum() {
return randomNum;
}
public String getID() {
return ID;
}
}
class RandomText {
public static void main(String[] args) {
int ans = Integer.parseInt(JOptionPane.showInputDialog("How many random number you want to show?"));
ArrayList < Random > randomNum = new ArrayList < Random > ();
for (int i = 0; i < ans; i++) {
randomNum.add(new Random("ID " + Integer.toString(i), 0));
}
String result;
for (int i = 0; i < ans; i++) {
result = result + ?????? +"\n";
}
JOptionPane.showMessageDialog(null, result ")
}
}