109.1.. Učitati dva dvodimenzionalna niza i formirati treći čiji je opšti član: cij = xij - yij.

Listing programa:



package zad1;
import java.util.Scanner;
public class P10912103{

	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);

		System.out.print("unesi broj redova i kolona ");

		int r = input.nextInt();
		int k = input.nextInt();
		int x[][] = new int[r][k];
		int y[][] = new int[r][k];
		int c[][] = new int[r][k];

		System.out.print("unesi clanove matrice X ");
		for (int i = 0; i < x.length; i++) {
			for (int j = 0; j < x.length; j++) {
				System.out.print("X[" +i+ "," +j +"]"+ "-->");
				x[i][j] = input.nextInt();			}
		}
		System.out.print("unesi clanove matrice Y ");
		for (int i = 0; i < y.length; i++)
			for (int j = 0; j < y.length; j++) {
				System.out.print("Y[" +i+ "," +j +"]"+ "-->");
				y[i][j] = input.nextInt();
			}
		// c matrica
		for (int i = 0; i < y.length; i++)
			for (int j = 0; j < y[i].length; j++) {
				c[i][j] = x[i][j] - y[i][j];
			}

		System.out.println();
		System.out.println("Matrica X");
		for (int i = 0; i < x.length; i++) {
			for (int j = 0; j < x[i].length; j++)
				System.out.print(x[i][j] + " ");
			System.out.println();
		}
		System.out.println("Matrica Y");
		for (int i = 0; i < y.length; i++) {
			for (int j = 0; j < y[i].length; j++)
				System.out.print(y[i][j] + " ");
			System.out.println();
		}
		System.out.println();
		System.out.println("Matrica C");
		for (int i = 0; i < y.length; i++) {
			for (int j = 0; j < y[i].length; j++)
				System.out.print(c[i][j] + " ");
			System.out.println();
		}
	}
}

II Varijanta
package zad1;
import java.util.Scanner;
public class P10912103{

	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);

		System.out.print("unesi broj redova i kolona ");

		int r = input.nextInt();
		int k = input.nextInt();
		int x[][] = new int[r][k];
		int y[][] = new int[r][k];

		System.out.print("unesi clanove matrice X ");
		for (int i = 0; i < x.length; i++) {
			for (int j = 0; j < x[i].length; j++) {
				int clan = input.nextInt();
				x[i][j] = clan;
			}
		}
		System.out.print("unesi clanove matrice Y ");
		for (int i = 0; i < y.length; i++)
			for (int j = 0; j < y[i].length; j++) {
				int clan = input.nextInt();
				y[i][j] = clan;
			}
		System.out.println();
		System.out.println("Matrica X");
		for (int i = 0; i < x.length; i++) {
			for (int j = 0; j < x[i].length; j++)
				System.out.print(x[i][j] + " ");
			System.out.println();
		}
		System.out.println("Matrica Y");
		for (int i = 0; i < y.length; i++) {
			for (int j = 0; j < y[i].length; j++)
				System.out.print(y[i][j] + " ");
			System.out.println();
		}
		System.out.println();
		System.out.println("Matrica C");
		for (int i = 0; i < y.length; i++) {
			for (int j = 0; j < y[i].length; j++)
				System.out.print((x[i][j] - y[i][j]) + " ");
			System.out.println();
		}
	}
}

Ispis na ekranu:

Index