Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package matriz;
- import java.util.Scanner;
- public class ex3loiane {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- int [][] numeros = new int [3][3];
- // receber numeros da matriz
- for(int i = 0; i < numeros.length; i++){
- for(int j = 0; j < numeros[i].length; j++){
- System.out.println("Digite o valor da posição ["+ i+","+j+"] : ");
- numeros[i][j] = sc.nextInt();
- }
- }
- //qtd num pares e impares
- int qtdpares = 0;
- int qtdimpares = 0;
- for(int i = 0; i< numeros.length; i++){
- for(int j = 0; j < numeros[i].length; j++){
- if(numeros[i][j] % 2 == 0){
- qtdpares++;
- }else{
- qtdimpares++;
- }
- }
- }
- // mostrar a matriz
- for(int i = 0; i < numeros.length; i++){
- for(int j = 0; j< numeros[i].length; j++){
- System.out.print(numeros[i][j]+ " ");
- }
- System.out.println();
- }
- System.out.println("Qtd num pares: "+qtdpares);
- System.out.println("Qtd num impares: "+qtdimpares);
- }
- /* César N. */
- }
- //Capturar do teclado valores de preenchimento de uma matriz 3x3.
- //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