• Lunes 29 de Abril de 2024, 21:58

Autor Tema:  Necesito De Ustds Para Encontrar El Error  (Leído 1002 veces)

digichap28

  • Miembro activo
  • **
  • Mensajes: 64
    • Ver Perfil
Necesito De Ustds Para Encontrar El Error
« en: Sábado 17 de Noviembre de 2007, 01:37 »
0
Hola que tal como estan??
Bueno yo no tan bien, esto es urgente, necesito de su ayuda por favor.
Es una de las notas finales del semestre.

Aqui va lo que hice, no entiendo porque no me escribe nada!!! Que esta pasando ??? no tengo ni idea!!! ya revise el codigo pero no encuentro problemas(por lo menos hasta donde yo veo).
ES UN RECORRIDO DE MATRIZ.


Citar
import javax.swing.*;
public class recorrido {

    public static void main (String [] args) {
       int i,j,k,n,m,s;
       int a[][] = new int [10][10];
       int v[] = new int [100];
       String st;
       
       n=Integer.parseInt(JOptionPane.showInputDialog("n° filas"));
       m=Integer.parseInt(JOptionPane.showInputDialog("n° columnas"));
       for (i=1;i<=n;i++){
      for(j=1;j<=m;j++){
         a[j]=Integer.parseInt(JOptionPane.showInputDialog("a[ "+i+j+ " ]="));
      }
       }
       
       
       if(n % 2==0){
      k=0;
      for(i=n;i<=1;i--){
         if(i % 2==0){
        for(j=m;j<=1;j--){
           k++;
           v[k]=a[j];
        }
         }else{
        for (j=1;j<=m;j++){
           k++;
           v[k]=a[j];
        }
     
         }
      }
       }else{
      k=0;
      for(i=n;i<=1;i--){
         if(i % 2!=0){
        for(j=m;j<=1;j--){
           k++;
           v[k]=a[j];
        }
         }else{
           for(j=1;j<=m;j++){
           k++;
           v[k]=a[j];
        }
         }   
      }       
         
    }
    st=" ";
       for (s=1;s<=k;s++){
         st= st + v + " ";
       }
       JOptionPane.showMessageDialog(null, st );
       
  }
}
       
   

ESTE ES EL RECORRIDO QUE DEBE HACERSE.
   
       
        ETCETERA
     |  <-------- |
     |  --------> |
     |  <-------- |
     |  --------> |
     |  <-------- | (inicio)

logicaemp

  • Miembro activo
  • **
  • Mensajes: 32
    • Ver Perfil
Re: Necesito De Ustds Para Encontrar El Error
« Respuesta #1 en: Sábado 17 de Noviembre de 2007, 22:44 »
0
Tienes que hacer los 4 cambios indicados en el siguiente código:

Código: Text
  1. import javax.swing.*;
  2. public class recorrido {
  3.  
  4.     public static void main (String [] args) {
  5.     int i,j,k,n,m,s;
  6.     int a[][] = new int [10][10];
  7.     int v[] = new int [100];
  8.     String st;
  9.    
  10.     n=Integer.parseInt(JOptionPane.showInputDialog(&#34;n° filas&#34;));
  11.     m=Integer.parseInt(JOptionPane.showInputDialog(&#34;n° columnas&#34;));
  12.     for (i=1;i&#60;=n;i++){
  13.       for(j=1;j&#60;=m;j++){
  14.       a[i][j]=Integer.parseInt(JOptionPane.showInputDialog(&#34;a[ &#34;+i+j+ &#34; ]=&#34;));
  15.       }
  16.     }
  17.    
  18.    
  19.     if(n % 2==0){
  20.       k=0;
  21.       for(i=n;i&#60;=1;i--){ //   **********  &#34;&#60;=&#34;  cambiar  &#34;&#62;=&#34;
  22.       if(i % 2==0){
  23.         for(j=m;j&#60;=1;j--){ //   **********  &#34;&#60;=&#34;  cambiar  &#34;&#62;=&#34;
  24.         k++;
  25.         v[k]=a[i][j];
  26.         }
  27.       }else{
  28.         for (j=1;j&#60;=m;j++){
  29.         k++;
  30.         v[k]=a[i][j];
  31.         }
  32.      
  33.       }
  34.       }
  35.     }else{
  36.       k=0;
  37.       for(i=n;i&#60;=1;i--){  //   **********  &#34;&#60;=&#34;  cambiar  &#34;&#62;=&#34;
  38.       if(i % 2!=0){
  39.         for(j=m;j&#60;=1;j--){  //   **********  &#34;&#60;=&#34;  cambiar  &#34;&#62;=&#34;
  40.         k++;
  41.         v[k]=a[i][j];
  42.         }
  43.       }else{
  44.         for(j=1;j&#60;=m;j++){
  45.         k++;
  46.         v[k]=a[i][j];
  47.         }
  48.       }
  49.       }  
  50.      
  51.     }
  52.     st=&#34; &#34;;
  53.     for (s=1;s&#60;=k;s++){
  54.       st= st + v[s] + &#34; &#34;;
  55.     }
  56.     JOptionPane.showMessageDialog(null, st );
  57.    
  58.   }
  59. }
  60.  

Saludos,

digichap28

  • Miembro activo
  • **
  • Mensajes: 64
    • Ver Perfil
Re: Necesito De Ustds Para Encontrar El Error
« Respuesta #2 en: Domingo 18 de Noviembre de 2007, 02:31 »
0
MUCHAASSS GRACIAS
THANKS A LOT
ARIGATOU

Y NO SE QUE OTRO IDIOMA  :D

NOTA:OJALA ESTE CODIGO LE SIRVA A ALGUIEN MAS  :hola:  :hola: