Given the code below I have to find a way to get a random value from the values: 100, 120, 140, 160, 180, 200, 220, 240, 260, 280. The catch is that I have to write a single statement (One semi-colon) that will randomly pick one of the ints and assign it into the random_int variable. Does anyone have any idea how I could create a list or array of the numbers above and pick a random int from the numbers to assign to random_int in a single statement? Thank you for the help!
public static void main(String[] args) {
Random random = new Random();
int random_int;
// Your single statement goes here
System.out.println(
“Number is: “ + random_int);
}
Aucun commentaire:
Enregistrer un commentaire