Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Tarefas_3;
- public class EX_02
- {
- public static void main(String[] args)
- {
- int linha = 10, coluna = 10;
- int matriz [][] = new int [linha][coluna];
- System.out.printf("\n # Media da diagonal principal: %.2f \n", (soma_diagonal_principal(linha, coluna, matriz) / linha) );
- }
- private static double soma_diagonal_principal(int linha, int coluna, int [][] matriz)
- {
- int num = 0, soma = 0;
- // Estrutura de repeticao: Matriz 10 x 10
- for (int i = 0; i < linha; i++)
- {
- for (int j = 0; j < coluna; j++)
- {
- matriz[i][j] = ++num;
- System.out.print("\t" + matriz[i][j]);
- if (i == j)
- {
- soma += matriz[i][j];
- }
- }
- System.out.println("");
- }
- return soma;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement