برنامه ای نوشتم که تعداد سطر و ستون رو و همچنین المانهای ماتریس رو از ورودی بگیره و به شکل مرتب چاپ کنه ولی برنامه در هنگام اجرا error میده .
این برنامه :
import java.util.*;public class matrix_print {
static Scaer console= new Scaer(System.in);
public static void main(String args[]) {
int row=0,col=0;
int [][] matrix = new int[row][col];
System.out.print("Enter Row and Col :");
row=console.nextInt();
col=console.nextInt();
System.out.print("Enter matrix elements :");
for (int i=0;i<row;i++){
for (int j=0;j<col;j++){
matrix[i][j]=console.nextInt();
}
}
for (int k=0;k<row;k++){
for (int l=0;l<col;l++){
System.out.print(matrix[k][l]+"t");
}
System.out.println();
}}
}
اینم ارورش :
Enter Row and Col :5 7Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
at matrix_print.main(matrix_print.java:13)
Enter matrix elements :
برچسب:
نویسنده: محمد رضا جوادیان