I am really new in Java. I have a question about put a set of array as 2d array. I really don't know how to do this with given array.This is my program
public static void main(String args[]){
int arr[][]= new int[5][5];
int[] number = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
int numberIndex=0;
for(int i=0; i < arr.length; i++){
arr[i] = new int[i+1];
for(int j=0; j<arr[i].length; j++){
arr[i][j] = number[numberIndex];
System.out.println(numberIndex);
numberIndex++;
}
}
}
Result is similar to this site, but it has to make by given array number Site
I understand the program below:( but i really don't know how to make it as array.)
public class RightAngledTriangleNumbers {
//void main
public static void main (String[] args)
{
//declare int
int i,j,n=1;
//for loops
for(i=1;i<=5;i++)
{
for(j=1;j<=i;j++)
{
System.out.print(n+" ");
n++;
}
System.out.print("n");
}
}
}