SoloCodigo
		Programación General => Java => Mensaje iniciado por: digichap28 en Viernes 30 de Noviembre de 2007, 00:43
		
			
			- 
				Este es un recorrido de matriz hecho por mi, mis preguntas son:
 Hay varias formas de escribir el recorrido?
 Cual es la forma mas rapida para este caso?
 Podrian poner su codigo a ver que tal y aprender??
 
 
 /**
 * @(#)recorrido.java
 *
 *              <------
 *              ------>
 *              <------ inicio
 *
 *
 * @version 1.00 2007/11/16
 */
 
 
 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 );
 
 }
 }
 
 
 
 
 
 GRACIAS