-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path16 .2D Array.java
More file actions
47 lines (40 loc) · 1.1 KB
/
16 .2D Array.java
File metadata and controls
47 lines (40 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package test;
import java.util.Arrays;
import java.util.Scanner;
//import javax.swing.*;
//import java.lang.Math;
//import java.util.Random;
//import java.awt.Color; // abstract window toolkit
import java.util.Arrays;
public class main {
// Two dimensional array list (2D).
// 2D examples:
//
public static void main(String[] args) {
// TODO Auto-generated method stub
// Declare the Scanner library
Scanner scanner = new Scanner(System.in);
// Initializing a 2D array with predefined values:
int [][] numbers = {
{1,2,3,4,5},
{6,7,8,9,10},
{11,12,13,14,15}
};
System.out.println(numbers[1][3]);
// Initializing a 2D array with a loop
int [][] numbers_0_value = new int[5][5];
// numbers_0_value[0][0] = 5;
// numbers_0_value[0][1] = 7;
// numbers_0_value[0][2] = 5;
int res = 0;
for(int i = 0; i < numbers_0_value.length; i++) {
for(int j = 0; j < numbers_0_value[i].length; j++) {
res++;
numbers_0_value[i][j] = res;
System.out.print(numbers_0_value[i][j] + "\t");
}
System.out.println();
}
// System.out.println(numbers_0_value[0][1]);
}
}