Advertisement
vinedfs

Matriz1

Jul 23rd, 2014
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.83 KB | None | 0 0
  1. package br.com.geracao.base.main;
  2.  
  3. import javax.swing.JOptionPane;
  4.  
  5.  
  6. public class MainApplication {
  7.    
  8.     public static void main(String[] arg) {
  9.        
  10.         int linhas = Integer.parseInt(JOptionPane.showInputDialog("Quantas linhas?"));
  11.         int colunas = Integer.parseInt(JOptionPane.showInputDialog("Quantas colunas?"));
  12.        
  13.         int[][] matriz = new int[linhas][colunas];
  14.        
  15.         for (int i = 0; i < matriz.length; i++) {
  16.             for (int j = 0; j < matriz[i].length; j++) {
  17.                 if (j % 2 == 0) {
  18.                     matriz[i][j] = 0;
  19.                 } else {
  20.                     matriz[i][j] = 1;
  21.                 }
  22.             }
  23.         }
  24.        
  25.         exibirMatriz(matriz);
  26.        
  27.     }
  28.  
  29.     private static void exibirMatriz(int[][] matriz) {
  30.         for (int i = 0; i < matriz.length; i++) {
  31.             for (int j = 0; j < matriz[i].length; j++) {
  32.                 System.out.print(matriz[i][j] + " ");
  33.             }
  34.             System.out.println();
  35.         }
  36.        
  37.     }
  38.    
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement