mirror of
https://gitlab.com/tutorial-java-rafa-munoz/tutorial-java-2024-25/tutorialjava2024-25.git
synced 2025-11-09 09:57:40 +01:00
feat(cp 4): solved blocks 7 & 8
This commit is contained in:
@@ -20,6 +20,10 @@ public class Ej02_CiclicoEnArrayRespetandoIntervaloInterior {
|
||||
}
|
||||
} while (posIni > posFin);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
int aux = a[a.length - 1];
|
||||
|
||||
for (int i = a.length - 2; i > -1; i--) {
|
||||
|
||||
@@ -7,7 +7,7 @@ public class Ej04_MinYMaxEnMatriz {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
int m[][] = UtilsArrays.creaEInicializaMatriz(6, 10, -1);
|
||||
int m[][] = new int[6][10];
|
||||
|
||||
for (int i = 0; i < m.length; i++) {
|
||||
for (int j = 0; j < m[i].length; j++) {
|
||||
@@ -25,16 +25,26 @@ public class Ej04_MinYMaxEnMatriz {
|
||||
UtilsArrays.imprimeMatriz(m);
|
||||
|
||||
// Obtengo min y max
|
||||
int filaMin = 0, filaMax = 0, colMin = 0, colMax = 0;
|
||||
int min = m[0][0];
|
||||
int max = m[0][0];
|
||||
for (int i = 0; i < m.length; i++) {
|
||||
for (int j = 0; j < m[i].length; j++) {
|
||||
if (m[i][j] > max) max = m[i][j];
|
||||
if (m[i][j] < min) min = m[i][j];
|
||||
if (m[i][j] > max) {
|
||||
max = m[i][j];
|
||||
filaMax = i;
|
||||
colMax = j;
|
||||
}
|
||||
if (m[i][j] < min) {
|
||||
min = m[i][j];
|
||||
filaMin = i;
|
||||
colMin = j;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println("Máximo: " + max + " - Mínimo: " + min);
|
||||
System.out.println("Máximo: " + max + "(" + filaMax + ", " + colMax +
|
||||
") - Mínimo: " + min + "(" + filaMin + ", " + colMin + ")");
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -8,18 +8,12 @@ import tutorialJava.UtilsArrays;
|
||||
public class Ej06_PosiblesMovimientosAlfil {
|
||||
|
||||
public static void main(String[] args) {
|
||||
// String cabecerasFilas = "abcdefgh";
|
||||
int xAlfil, yAlfil;
|
||||
int tablero[][] = UtilsArrays.creaEInicializaMatriz(8, 8, 0);
|
||||
|
||||
System.out.println("Tablero del ajedrez");
|
||||
UtilsArrays.imprimeMatriz(tablero);
|
||||
|
||||
// System.out.println("Dame la letra de la fila: ");
|
||||
// Scanner sc = new Scanner(System.in);
|
||||
// char letraFila = sc.nextLine().charAt(0);
|
||||
// yAlfil = cabecerasFilas.indexOf(letraFila);
|
||||
|
||||
yAlfil = Utils.obtenerEnteroEntreLimites("Introduzca la fila del Alfil", 1, 8) - 1;
|
||||
|
||||
xAlfil = Utils.obtenerEnteroEntreLimites("Introduzca la columna del Alfil", 1, 8) - 1;
|
||||
|
||||
Reference in New Issue
Block a user