elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Únete al Grupo Steam elhacker.NET


  Mostrar Temas
Páginas: [1]
1  Programación / Java / Arreglos Bidimensionales en: 9 Febrero 2021, 05:43 am
/*
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)
*/
Código
  1. package pregunta1_pab;
  2.  
  3. import javax.swing.JOptionPane;
  4.  
  5. public class Pregunta1_PAB {
  6. static int m=Integer.parseInt(JOptionPane.showInputDialog("Ingresar el tamaño de las filas del arreglo : "));
  7. static int n=Integer.parseInt(JOptionPane.showInputDialog("Ingresar el tamaño de las columna del arreglo : "));
  8. static int num[][]=new int [m][n],auxCapicuaPrincipal,cifra,CapicuaNumero,NumeroPrincipal,respuestaPrincipal,auxMayor,NumeroP;
  9. static int auxCapicuaSecundario;
  10. public static void main(String[] args) {
  11. ingresar();
  12. mostrar();
  13. diagonales();
  14. }
  15. public static void ingresar(){
  16. for(int i=0;i<m;i++){
  17. for(int k=0;k<n;k++){
  18.  
  19. num[i][k]=Integer.parseInt(JOptionPane.showInputDialog("Ingrese un numero entero mayor de una cifra : "));
  20.  
  21. }
  22. }
  23.  
  24. }
  25.  
  26. public static void mostrar(){
  27.  
  28. for(int i=0;i<m;i++){
  29. for(int k=0;k<n;k++){
  30. System.out.print(num[i][k]+" ");
  31. }
  32. System.out.println("");
  33. }
  34. }
  35.  
  36. public static void diagonales(){
  37.  
  38. for(int i=0; i<m;i++){
  39. for(int k=0; k<n;k++){
  40.  
  41. if(i==k){
  42. CapicuaNumero=0;
  43. auxMayor=0;
  44. auxCapicuaPrincipal=num[i][k];
  45.  
  46. while(auxCapicuaPrincipal>0){
  47. cifra = auxCapicuaPrincipal%10;
  48. auxCapicuaPrincipal=auxCapicuaPrincipal/10;
  49. //CapicuaNumero = 0
  50. NumeroPrincipal=(CapicuaNumero*10)+cifra;
  51. }
  52. if(NumeroPrincipal==num[i][k]){
  53.  
  54. if(NumeroPrincipal>auxMayor){
  55. NumeroP = respuestaPrincipal;
  56. }
  57. }
  58.  
  59.  
  60. System.out.println("numero capicua"+NumeroP);
  61. }
  62. /*if((i+k)==num.length-1){
  63. auxCapicuaSecundario=num[i][k];
  64. }*/
  65. }
  66. }
  67. JOptionPane.showMessageDialog(null,"El mas alto numero es "+NumeroP);
  68.  
  69.  
  70. }
  71.  
  72. }
  73.  
-------------------------------------------------------------------------------------------------------
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.

[MOD] usar etiquetas GeSHi para publicar codigo.
Páginas: [1]
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines