109.3.. Učitati dvodimenzionalni niz - matricu nxm. Naći i ispisati najveći elemenat matrice X[n,m].

Opis programa:

Tekstualni algoritam:

Listing programa:


package prvipaket;
import java.util.Scanner;
public class P10917001 {

	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		System.out.print("n(kvadratna matrica)  ");

		int n = input.nextInt();
		int niz[][] = new int[n][n];

		System.out.print("unesi clanove ");
		for (int i = 0; i < niz.length; i++) {
			for (int j = 0; j < niz[i].length; j++) {
				System.out.print("X[" +i+ "," +j +"]"+ "-->");
				niz[i][j] = input.nextInt();
			}
		}
		for (int i = 0; i < niz.length; i++) {
			System.out.println();
			for (int j = 0; j < niz[i].length; j++) {
				System.out.print(niz[i][j] + " ");
			}
		}
		System.out.println();
		int max = niz[0][0];
		for (int i = 0; i < niz.length; i++) {
			for (int j = 0; j < niz[i].length; j++) {
				if (max < niz[i][j])
					max = niz[i][j];
			}
		}
		System.out.print("Najveci clan matrice: " + max);
	}
}

Ispis na ekranu:

Index