from the input:
java Solematrix 4
4 is variable
print out :1 0 0 0
0 1 0 0
0 0 1 0
0 0 0 1
------------------------------------
code:
public class Solematrix{
public static void main(
String[] args){
int n=0;
n= Integer.parseInt(args[0]);
int[][] m=new int[n][n];
for(int i=1; i<=n; i++){
for(int j=1; j<=n; j++){
if(i==j)
m[i][j]=1;
else
m[i][j]=0;
}
}
for(int i=1; i<=n; i++){
if(i!=1){System.out.print("");}
for(int j=1; j<=n; j++){
System.out.print(m[i][j]+", ");
}
}
}
}
------
tcf% javac Solematrix.java
tcf% java Solematrix
Exception in
thread "main" java.lang.ArrayIndexOutOfBoundsException: -1
at Solematrix.main(Compiled Code)
-----
I dont understand what the exception say
anybody can help or modify for the code
thanks a lot
brokeybin