I'm having trouble with a java code. I am trying to make a code which generates a 3x3 array. I made a code which at first sight works okay.
matrix3x3
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();
}}
But try to put 2 numbers in the field to fill the array, for example
3x3 array
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();
}}
There is a big mistake and the code no longer works, I'm looking for my error, but I'm new to Java and I ask for your help. 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)