Ayuda por favor sobre arreglos bidimensionales
Publicado por Marthy (11 intervenciones) el 09/02/2021 01:35:54
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
69
70
71
72
73
74
75
76
77
78
/*
DISEÑAR UN PROGRAMA QUE INGRESE NUMEROS ENTEROS A UN ARREGLO BIDIMENSIONAL SE PIDE CALCULAR
E IMPRIMIR EL SEGUNDO NUMERO CAPICUA MAS ALTO DE CADA DIAGONAL PRINCIPAL DEL ARREGLO
(CUANDO M=N). (NO USAR ARREGLO LINEAL)
*/
package pregunta1_pab;
import javax.swing.JOptionPane;
public class Pregunta1_PAB {
static int m=Integer.parseInt(JOptionPane.showInputDialog("Ingresar el tamaño de las filas del arreglo : "));
static int n=Integer.parseInt(JOptionPane.showInputDialog("Ingresar el tamaño de las columna del arreglo : "));
static int num[][]=new int [m][n],auxCapicuaPrincipal,cifra,CapicuaNumero,NumeroPrincipal,respuestaPrincipal,auxMayor,NumeroP;
static int auxCapicuaSecundario;
public static void main(String[] args) {
ingresar();
mostrar();
diagonales();
}
public static void ingresar(){
for(int i=0;i<m;i++){
for(int k=0;k<n;k++){
num[i][k]=Integer.parseInt(JOptionPane.showInputDialog("Ingrese un numero entero mayor de una cifra : "));
}
}
}
public static void mostrar(){
for(int i=0;i<m;i++){
for(int k=0;k<n;k++){
System.out.print(num[i][k]+" ");
}
System.out.println("");
}
}
public static void diagonales(){
for(int i=0; i<m;i++){
for(int k=0; k<n;k++){
if(i==k){
CapicuaNumero=0;
auxMayor=0;
auxCapicuaPrincipal=num[i][k];
while(auxCapicuaPrincipal>0){
cifra = auxCapicuaPrincipal%10;
auxCapicuaPrincipal=auxCapicuaPrincipal/10;
//CapicuaNumero = 0
NumeroPrincipal=(CapicuaNumero*10)+cifra;
}
if(NumeroPrincipal==num[i][k]){
if(NumeroPrincipal>auxMayor){
NumeroP = respuestaPrincipal;
}
}
System.out.println("numero capicua"+NumeroP);
}
/*if((i+k)==num.length-1){
auxCapicuaSecundario=num[i][k];
}*/
}
}
JOptionPane.showMessageDialog(null,"El mas alto numero es "+NumeroP);
}
}
-------------------------------------------------------------------------------------------------------
CUANDO CORRE E INGRESO DATOS ME SALE:
- EL MAS ALTO NUMERO ES 0
- NUMERO CAPICUA 0
ME PUEDEN AYUDAR QUE ES LO QUE ESTÁ MAL, GRACIAS.
Valora esta pregunta


0