Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class II08022013 {
- private static Scanner in = new Scanner(System.in);
- public static int[][] lerMatriz(int n){
- int[][] m = new int[n][n];
- for(int i=0;i<n;i++){
- for(int j=0;j<n;j++){
- System.out.print("MAT["+i+"]["+j+"]=");
- m[i][j]=in.nextInt();
- }
- }
- return m;
- }
- public static void mostrarMatriz(int[][] m){
- for(int i=0;i<m.length;i++){
- for(int j=0;j<m[0].length;j++){
- System.out.print(m[i][j]+" ");
- }
- System.out.println();
- }
- }
- public static void listarVetor(int[] v, int n){
- for(int i=0;i<n;i++){
- System.out.println(v[i]);
- }
- }
- public static int imparesDePares(int[][] m, int[] v){
- int nv=0;
- for(int i=0;i<m.length;i+=2){
- for(int j=0;j<m[0].length;j++){
- if(m[i][j]%2!=0){
- v[nv]=m[i][j];
- nv++;
- }
- }
- }
- return nv;
- }
- public static void trocarElementos(int[][] m){
- for(int i=0;i<m.length-1;i++){
- for(int j=0;j<m[0].length-1-i;j++){
- int temp=m[i][j];
- m[i][j]=m[m[0].length-j-1][m.length-i-1];
- m[m[0].length-j-1][m.length-i-1]=temp;
- }
- }
- }
- public static void main(String[] args) {
- System.out.print("Matiz Quadrada de Ordem N?");
- int nm = in.nextInt();
- while(nm<2){
- System.out.println("ERRO: Ordem Invalida");
- System.out.print("Matiz Quadrada de Ordem N?");
- nm = in.nextInt();
- }
- int[][] mat=lerMatriz(nm);
- System.out.println();
- System.out.println("Impares de Pares");
- int[] vec = new int[(nm)*1000];
- int nv=imparesDePares(mat,vec);
- listarVetor(vec,nv);
- System.out.println();
- mostrarMatriz(mat);
- trocarElementos(mat);
- System.out.println("Troca de Elementos");
- mostrarMatriz(mat);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement