Today, I occasionally made a Java question and was directly despised.
PostCode
Package test; public class demo {public static void main (string [] ARGs) {int I = 10; Switch (I) {default: system. out. println ("default"); Case 0: system. out. println ("0"); break; Case 1: system. out. println ("1"); Case 2: system. out. println ("2 ");}}}
Default0
The result is this, which gets the switch operation mechanism. No matter how the switch is written, the number in the case is first determined. Therefore, wherever the default is written, the case statement is first executed.
The focus is on the following. If this value exists in case, execute the statements in this case directly. If this value is not available, the system will find default. Run the default command until the break is executed. So unfortunately, I didn't learn the C language well... It's a tragedy. Let's make up for it during the winter vacation.
Another trap is &, | and &, |. The former has a short circuit function, while the latter does not. I remember it, so I failed the exam ..
Another trap is the Java string array. Although the string is a class, this class is special and can be used in this way.
String a [] = {"", ""}; // The correct string AA [] = new string [5]; // It is also correct AA [0] = "123"; system. out. println (AA [0]);
However, for a custom class, it is very different from the string class.
Package test; import B. student; public class demo {public static void main (string [] ARGs) {student s [] = new student [5]; s [0]. setname ("AAA"); system. out. println (s [0]. getname ());}}
In this way, a null pointer exception occurs.
Exception in thread "Main" Java. Lang. nullpointerexceptionat test. Demo. Main (Demo. Java: 8)
I personally think C and Java are really profound and profound, and there are too many things. It is worth studying.
There is also a small trap
The length of the array is. length.
The string length is. Length ()
The list size is. Size ()