+ 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++)
3 odpowiedzi
+ 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]);
}
}
}
}
+ 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
0
in cpp I would do it like that:
https://code.sololearn.com/czimP7vjbzHb/?ref=app