109.1.. Učitati dvodimenzionalni niz i formirati drugi čiji je opšti član: yi,j = xi,j za i+j parno, inače je yi,j = 2.
Listing programa:
package zad1;
import java.util.Scanner;
public class P10912024 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("unesi broj redova i kolona");
int n = input.nextInt();
int m = input.nextInt();
int x[][] = new int[n][m];
System.out.print("unesi clanove niza x");
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
x[i][j] = input.nextInt();
}
}
int y[][] = new int[n][m];
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if ((i + j) % 2 == 0)
y[i][j] = x[i][j];
else
y[i][j] = 2;
}
}
System.out.println();
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
System.out.print(x[i][j] + " ");
}
System.out.println();
}
System.out.println();
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
System.out.print(y[i][j] + " ");
}
System.out.println();
}
}
}
Ispis na ekranu:
Index
|