Duvida Iniciante

2 respostas
F
import java.util.*;  
   public class Main {  
     
       /** 
        * @param args the command line arguments 
        */  
     
    
       /*    private static MAXLINHAS = 20; 
         private static MAXCOLUNAS = 20;*/  
     
       public static void main (String [] args){  
     
           Scanner sc = new Scanner(System.in);  
     
           //lê o numero de linhas  
           System.out.print("Quantas linhas tem a matriz? ");  
             
           int nLinhas=sc.nextInt();  
           // lê o numero de colunas  
           System.out.print("E quantas colunas ");  
             
           int nColunas=sc.nextInt();  
                   //declara e lê a matriz  
           int [][] matriz = leMatriz(nLinhas,nColunas, sc);  
     
           //imprime a matriz no écran para verificação  
           for(int i=0; i<nLinhas; i++){  
               for(int j=0;j<nColunas;j++)  
               System.out.print(matriz[i][j]+" ");  
               System.out.println();  
           }  
     
       }  
     
       public static int[][] leMatriz(int nLinhas, int nColunas, Scanner sc){  
     
           int [][] matriz = new int [nLinhas][nColunas];  
         
       for (int i=0;i<nLinhas;i++)  
           for(int j=0;j<nColunas;j++)  
               matriz[i][j]=leIntPositivo(sc);  
       return matriz;  
       }  
     
     
       public static int leIntPositivo(Scanner sc){  
       int n = -1;  
       do {System.out.print(" :");  
           if (sc.hasNextInt()) n = sc.nextInt();  
           else {sc.next();  
           n = -1;}  
       } while (n <= 0);  
      return n;  
       }  
     
  public static int trasPosta (int [][] entrada){  
      int [][] matriztrasposta=new int [entrada[0].length][entrada.length];  
      int [][]teste=new int [][];  
     for (int i=0;i<entrada[0].length;i++)  
          for (int j=0;j<entrada.length;j++)  
     teste[i][j]= matriztransposta[j][i];  
     
     
  }
Ola a todos estou cm duvida neste exercicio ,o ultimo metodo deve transpor a matriz mas n estou fazendo certo penso eu agradecia se alguem pudesse me ajudar em onde esta meu erro n estou conseguindo descobrir .. Meu problema e em inverter a matriz ou seja

4 5 6 7 8
2 3 4 5 6 matriz normal
---------
---
4 2
5 3
6 4 matriz transposta
7 5
8 6
Sei que isto e bem simples mas n estou conseguindo ...desde ja agradeço ...

2 Respostas

drsmachado

Dá uma pesquisada, essa semana foi respondido um tópico com a mesma dúvida e com a mesma matriz.

ViniGodoy

E que, aliás, era seu também, fc40950.

Não duplique tópicos.

O tópico original: http://www.guj.com.br/posts/list/225583.java

Criado 27 de novembro de 2010
Ultima resposta 27 de nov. de 2010
Respostas 2
Participantes 3