Skip to content

Commit be9a191

Browse files
author
Ariadne Pinheiro
committed
Laço de Repetição for e uso com arrays
1 parent 4635c81 commit be9a191

File tree

1 file changed

+21
-9
lines changed

1 file changed

+21
-9
lines changed

src/main/java/com/example/AppArrays.java

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@
44

55
public class AppArrays {
66
public static void main(String[] args) {
7+
/*
78
int x = 10;
89
System.out.println(x);
910
1011
x = 20;
1112
System.out.println(x);
1213
1314
double vetorDouble[] = {10, 20, 30};
14-
System.out.println(Arrays. toString(vetorDouble));
15+
System.out.println(Arrays.toString(vetorDouble));
1516
1617
System.out.println("Valor da posição 0: " + vetorDouble[0]);
1718
System.out.println("Valor da posição 1: " + vetorDouble[1]);
@@ -20,18 +21,29 @@ public static void main(String[] args) {
2021
vetorDouble[0] = 1;
2122
System.out.println("Valor da posição 0: " + vetorDouble[0]);
2223
23-
int vetor3[] = new int[4];
24-
vetor3[0] = 100;
25-
vetor3[1] = 200;
26-
vetor3[2] = 300;
27-
vetor3[3] = 400;
24+
int vetor3[] = new int[5];
25+
for (int i = 0; i < vetor3.length; i++) {
26+
vetor3[i] = 100 * (i + 1);
27+
}
2828
System.out.println(Arrays.toString(vetor3));
29-
30-
double matriz[][] = { {10,20,30}, {40,50,60} };
29+
3130
matriz[0][1] = -20;
3231
matriz[1] = new double[]{70,80};
3332
System.out.println(Arrays.toString(matriz[0]));
3433
System.out.println(Arrays.toString(matriz[1]));
35-
34+
*/
35+
36+
double matriz[][] = new double[3][4];
37+
for (int i = 0; i < matriz.length; i++) {
38+
for (int j = 0; j < matriz[i].length; j++) {
39+
matriz[i][j] = (i * matriz[i].length + j+1) * 10;
40+
}
41+
}
42+
43+
for (int i = 0; i < matriz.length; i++) {
44+
for (int j = 0; j < matriz[i].length; j++) {
45+
System.out.printf("%5.1f ", matriz[i][j]);
46+
}
47+
}
3648
}
3749
}

0 commit comments

Comments
 (0)