Pit 1
public class Testdemo {
public static void Main (string[] args) {
SYSTEM.OUT.PRINTLN (Test ("0") + "," +test (NULL) + "," +test ("66"));
}
public static int test (String str) {
try {
Return Str.charat (0)-' 0 ';
} catch (NullPointerException e) {
return 2;
} catch (Indexoutofboundsexception e) {
return 3;
} catch (Exception e) {
return 4;
}finally{
return 5;
}
}
}
Print three 5,finally{} The contents of the code block are bound to run and will produce an overlay.
Str.charat (0)-' 0 '; The line code returns the character of STR subscript 0 compared to ' 0 ', and if so, returns 0, otherwise-1;
such as ' 123 '. CharAt (0)-' 1 ' is 0; ' 123 '. CharAt (0)-' 1 ' is-1;
Pit 2
public class Test {
public static void Main (string[] args) {
int sum=0;
for (int i=0;i<10;i++) {
sum=sum++;
}
SYSTEM.OUT.PRINTLN (sum);
}
}
The result of printing is 0, because it is sum++, not ++sum;
Java Foundation into pit set