Ayuda java bucle for, no lo entiendo.
Publicado por Gerardo (3 intervenciones) el 28/12/2019 17:26:05
Porque pone " j < i " en el minuto 4:00 aprox. ?, no entiendo si j en la primera vuelta va valer 1 por lo tanto " j < i " no se cumple, ya que j == 1 y i == 0, ? alguien me puede explicar? ( cabe aclarar que si se cumple en el bucle explicado por el chabon de java ats )
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
67
68
// EJERCICIO 3
package pr4ctica;
import java.util.Scanner;
public class pr4ctica {
public static void main(String[] args){
Scanner in = new Scanner(System.in);
// variables
int matriz[][];
int filas, columnas, cambio = 0;
// constantes
// algoritmos
System.out.print("Cuantas filas tendra su matriz ? : ");
filas = in.nextInt();
System.out.print("Cuantas columnas tendra su matriz ? : ");
columnas = in.nextInt();
matriz = new int[filas][columnas];
for(byte i = 0; i<filas ; i++){
for(byte j = 0; j<columnas ; j++){
System.out.print("Digite un valor [" +i+ "] [" +j+ "] :");
matriz[i][j] = in.nextInt();
}
}
for(int i = 0; i<3 ; i++){
for(int j = 0; j<i ; j++){ // ACA EL PROBLEMA v:
cambio = matriz[i][j];
matriz[i][j] = matriz[j][i];
matriz[j][i] = cambio;
}
}
for(byte i = 0; i<filas; i++){
for(byte j = 0; j<columnas; j++){
System.out.print(matriz[i][j] + " ");
}
System.out.println();
}
}
}
Valora esta pregunta


0