ahavat / poo-exemplo

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

poo-exemplo

package application;

import java.util.Scanner;

public class Program {

public static void main(String[] args) {

	Scanner sc = new Scanner(System.in);

	int n = sc.nextInt();

	int[][] mat = new int[n][n];

	for (int i = 0; i < mat.length; i++) {
		for (int j = 0; j < mat[i].length; j++) {
			mat[i][j] = sc.nextInt();
		}

	}

	System.out.println("Main diagonal: ");
	for (int i = 0; i < mat.length; i++) {
		System.out.println(mat[i][i] + " \n");
	}

	int count = 0;

	for (int i = 0; i < mat.length; i++) {
		for (int j = 0; j < mat[i].length; j++) {
			if (mat[i][j] < 0) {
				count++;
			}
		}
	}

	System.out.println("Negative numbers: " + count);
	sc.close();
}

}

About


Languages

Language:Java 100.0%