1.测试for循环的输出:
public class TestOutput {
public static void main(String[] args) {
int i = 0;
for (foo('A'); foo('B') && (i < 3); foo('C')) {
i++;
foo('D');
}
}
static boolean foo(char c) {
System.out.print(c);
return true;
}
}
输出结果为:
ABDCBDCBDCB
2.测试split的输出
public class TestOutput {
public static void main(String[] args) {
String info = "abcd|123||7899|sdfg";
for (String string : getString(info)) {
System.out.println(string);
}
}
public static String[] getString(String info) {
if (info == null) {
throw new NullPointerException("the info is null.");
}
String[] array = info.split("\\|");
return array;
}
}
输出结果为:
abcd
123
7899
sdfg
3.测试i++的输出:
public class TestOutput {
public static void main(String[] args) {
int i = 2;
i = i++;
int j = i++;
System.out.println(i + ":" + j);
}
}
输出结果为:
3:2
4.测试~的输出:
public class TestOutput {
public static void main(String[] args) {
int i = 0xFFFFFFFA;
int j = ~i;
System.out.println(i);
System.out.println(j);
System.out.println(~~i);
int t = 8;
System.out.println(~t);
int k = -9;
System.out.println(~k);
System.out.println(String.format("%1$04d", Integer.valueOf("0003")));
}
}
输出结果为:
-6
5
-6
-9
8
0003