+ 5

Best way to fill an Array

What is the best way to fill a 2d array of dimension 10X10 with numbers 1-100?(in Java and C++)

12th Feb 2018, 2:44 PM
Agnibha Chakraborty
Agnibha Chakraborty - avatar
3 ответов
+ 20
//a small correction @RandomCoder import java.util.Random; public class Program { public static void main(String[] args) { Random random = new Random(); int[][] array = new int [10][10]; for(int i = 0; i < array.length; i++){ for(int j = 0; j < array.length; j++){ array[i][j] = random.nextInt(100)+1; System.out.println(array[i][j]); } } } }
12th Feb 2018, 4:49 PM
Gaurav Agrawal
Gaurav Agrawal - avatar
+ 4
https://code.sololearn.com/caXmN6Hlwz2T/?ref=app This is the way I would use...maybe there are better ones but...it works for me :p I am filling it with random numbers from 1 to 100
12th Feb 2018, 2:54 PM
Sad
Sad - avatar
0
in cpp I would do it like that: https://code.sololearn.com/czimP7vjbzHb/?ref=app
20th Jan 2019, 8:55 PM
Daniel Möhring
Daniel Möhring - avatar