Jadval hosil qiling va unga ma’lumotlarni kiriting, ekranga chiqaring.
package com.company;
import java.util.Scanner;
public class Matrix {
public static void main(String[] args) {
Scanner string = new Scanner(System.in);
String[][] matrix = null;
int qator = 0;
int ustun = 0;
Scanner scanner = new Scanner(System.in);
System.out.print("Qator va ustunlarni kiriting : ");
qator = scanner.nextInt();
ustun = scanner.nextInt();
matrix = new String[qator][ustun];
System.out.println("Mattritaningementlarini kiriting ");
for (int i = 0; i < qator; i++) {
for (int j = 0; j < ustun; j++) {
System.out.print("Element[" + i + "][" + j + "]: ");
matrix[i][j] = string.nextLine();
}
}
System.out.println("\nJadval ");
for (String[] i : matrix) {
for (String j : i) {
System.out.print(j + " ");
}
System.out.println();
}
}
}
Do'stlaringiz bilan baham: |