0
I’m having difficulties in a java code. I’m trying to make a code that generates a 3x3 matrix. I made a code that at first glance works everything Okay.
matriz3x3
public static void main(String[] args) {
// TODO code application logic here
char[][] ch = {{'2','1','9'}, {'4','8','0'},{'7','5','3'}};
for (int i = 0; i < ch.length; i++) {
for (int j = 0; j < ch[i].length; j++) {
System.out.print("ch["+i+"]["+j+"] = "+ch[i][j]+"\t");
}
System.out.println();
}}
however when trying to put 2 numbers in the field which will fill the matrix, for example
3x3 matrix
public static void main(String[] args) {
// TODO code application logic here
char[][] ch = {{'20','10','90'}, {'40','80','01'},{'70','50','30'}};
for (int i = 0; i < ch.length; i++) {
for (int j = 0; j < ch[i].length; j++) {
System.out.print("ch["+i+"]["+j+"] = "+ch[i][j]+"\t");
}
System.out.println();
}}
gives a big error and no longer works the code, I am looking for my error, but I am new in Java and ask for the help of vcs. The errors that appear are: at java.lang.Classloader.defineClass1(Native Method) at java.lang.Classloader.defineClass(Classloader.java:763) at java.security.Secureclassloader.defineClass(Secureclassloader.java:142) at java.net.Urlclassloader.defineClass(Urlclassloader.java:467) at java.net.Urlclassloader.access$100(Urlclassloader.java:73) at java.net.Urlclassloader$1.run(Urlclassloader.java:368) at java.net.Urlclassloader$1.run(Urlclassloader.java:362) at java.security.Accesscontroller.doPrivileged(Native Method) at java.net.Urlclassloader.findClass(Urlclassloader.java:361) at java.lang.Classloader.loadClass(Classloader.java:424) at sun.misc.Launcher$Appclassloader.loadClass(Launcher.java:335) at java.lang.Classloader.loadClass(Classloader.java:357) at sun.launcher.Launcherhelper.checkAndLoadMain(Launcherhelper.java:495)
What error? Add the stack of errors in the question.
– user28595
The error that occurs is that the code simply does not work anymore, if put equal to the first code I put there, will generate the matrix and everything, but when I put equal to the second matrix nor generate more. .
– David Moreira
I edited and put the errors above
– David Moreira
It is not clear your problem. You say you error to "2 numbers in the field" but your code only lists the array elements. Which field? Edit the question and provide code that will codify the problem, because the code doesn’t have the problem you say it faces.
– user28595