Advertisement
cesarnascimento

cap do teclado matriz 3x3, impr pares e impares

Jun 5th, 2017
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.23 KB | None | 0 0
  1. package matriz;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class ex3loiane {
  6.  
  7.     public static void main(String[] args) {
  8.        
  9.         Scanner sc = new Scanner(System.in);
  10.        
  11.         int [][] numeros = new int [3][3];
  12.         // receber numeros da matriz
  13.         for(int i = 0; i < numeros.length; i++){
  14.             for(int j = 0; j < numeros[i].length; j++){
  15.                 System.out.println("Digite o valor da posição ["+ i+","+j+"] : ");
  16.                 numeros[i][j] = sc.nextInt();
  17.                
  18.             }
  19.         }
  20.         //qtd num pares e impares
  21.        
  22.         int qtdpares = 0;
  23.         int qtdimpares = 0;
  24.        
  25.         for(int i = 0; i< numeros.length; i++){
  26.             for(int j = 0; j < numeros[i].length; j++){
  27.                
  28.                 if(numeros[i][j] % 2 == 0){
  29.                     qtdpares++;
  30.                 }else{
  31.                     qtdimpares++;
  32.                 }
  33.             }
  34.         }
  35.        
  36.         // mostrar a matriz
  37.         for(int i = 0; i < numeros.length; i++){
  38.             for(int j = 0; j< numeros[i].length; j++){
  39.                 System.out.print(numeros[i][j]+ " ");
  40.             }
  41.             System.out.println();
  42.         }
  43.        
  44.        
  45.        
  46.         System.out.println("Qtd num pares: "+qtdpares);
  47.         System.out.println("Qtd num impares: "+qtdimpares);
  48.     }
  49.     /* César N. */
  50. }
  51.  
  52.  
  53. //Capturar do teclado valores de preenchimento de uma matriz 3x3.
  54. //Depois imprimir a matriz criada e encontrar a quantidade de números pares e a quantidade de números impares.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement