Answer to Question #83360 in Java | JSP | JSF for Ethan Goff

Question #83360
5 by 20 array is declared in the Java code (e.g., Data [i][j])
Data[i][0] always has year information which is ranged between 2005 and 2018
Data[i][0] should be randomly assigned
Data[i][1~19] has a random integer which is ranged between 1~100
1
Expert's answer
2018-11-27T11:59:10-0500
import java.util.Random;
class Main {
  public static void main(String[] args) {
    // create array
    int data[][] = new int[5][20];
    // loop over array
    for (int i = 0; i < 5; ++i) {
      // assign random value (in range 2005..2018)
      // for first element of subarray
      data[i][0] = random(2005, 2018);
      // loop over subarray starting from second element
      // and assign random value (in range 1..100)
      for (int j = 1; j < 20; ++j) {
        data[i][j] = random(1, 100);
      }
    }
  }
  // get random integer in range min..max
  public static int random(int min, int max) {
    Random rnd = new Random();
    return min + rnd.nextInt(max - min + 1);
  }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS