看到的一个题,随手分享一下

2017 年 2 月 10 日
 Famio
3739 次点击
所在节点    程序员
21 条回复
ArthurKing
2017 年 2 月 10 日
static void method(int a,int b){
System.out.println("a=100,b=200");
//throw new NullPointerException();
System.exit(0);
}
finalspeed
2017 年 2 月 10 日
楼上的 66666....
kaka8wp
2017 年 2 月 10 日
楼上的 66666....
fighter2011
2017 年 2 月 10 日
等待其他解答
ininit
2017 年 2 月 10 日
楼上的 666
qiayue
2017 年 2 月 10 日
@ArthurKing exit 哈哈哈
bianhua
2017 年 2 月 10 日
跟你们说吧,只有 1 楼的答案是对的,因为后面那两个它么是的 println (笑哭
ArthurKing
2017 年 2 月 10 日
@bianhua 不不不,还可以换成 while(true); ( ˙-˙ )
logbang
2017 年 2 月 10 日
楼上的 66666....
Famio
2017 年 2 月 10 日
@bianhua 哈哈哈,大兄弟是的。
jasontse
2017 年 2 月 10 日
套路。。。
haozibi
2017 年 2 月 10 日
1 楼真是简单粗暴
vh2h
2017 年 2 月 10 日
自古一楼出奇迹,看来没错啊!膜拜一楼。
aitaii
2017 年 2 月 10 日
正常的话是 a
b
aristotll
2017 年 2 月 10 日
第二种方法是啥 第一种我也想到了...
virusdefender
2017 年 2 月 10 日
valkyrja
2017 年 2 月 10 日
似乎可以覆盖 system.out.println 然后 replace?
padeoe
2017 年 2 月 11 日
长知识,帮补代码:
public static void method(int a, int b) {
System.setOut(new PrintStream(System.out) {
@Override
public void println(String s) {
super.println(s.equals("a=10") ? "a=100" : "b=200");
}
});
}
lxy42
2017 年 2 月 11 日
在 method 中打印结果后,将 stdout 重定向到 stderr
zhilincom
2017 年 2 月 11 日
@padeoe 应该是 super.print(s.equals("a=10") ? "a=100," : "b=200");

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://study.congcong.us/t/339610

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX