-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathArrays.java
66 lines (54 loc) · 2.05 KB
/
Arrays.java
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Main.java to edit this template
*/
package javaexercises;
import java.util.Scanner;
/**
*
* @author Laura Gómez Ruiz
*/
public class Arrays {
/**
* @param args the command line arguments1111111
*/
public static void main(String[] args) {
/************
STATIC ARRAY
************/
int staticArray [][] = new int [2][2];
staticArray [0][0] = 5;
staticArray [0][1] = 2;
staticArray [1][0] = 2;
staticArray [1][1] = 5;
System.out.println("Static Array: ");
System.out.print("[" + staticArray[0][0] + "]");
System.out.println("[" + staticArray[0][1] + "]");
System.out.print("[" + staticArray[1][0] + "]");
System.out.print("[" + staticArray[1][1] + "]");
System.out.println("");
/************
DINAMIC ARRAY
************/
int numColumns, numRows;
Scanner keyboard = new Scanner (System.in);
System.out.println("How many colums has your array?");
numColumns = keyboard.nextInt();
System.out.println("How many rows has your array?");
numRows = keyboard.nextInt();
int dinamicArray [][] = new int [numRows][numColumns];
for (int i = 0; i < numRows; i++) {
for (int j = 0; j < numColumns; j++) {
System.out.print("Introduce the number at " + (i+1) + " row and " + (j+1) + " colum: ");
dinamicArray[i][j] = keyboard.nextInt();
}
}
System.out.println("Our Dinamic Array: ");
for (int i = 0; i < numRows; i++) {
for (int j = 0; j < numColumns; j++) {
System.out.print("[" + dinamicArray[i][j] + "]");
}
System.out.println("");
}
}
}