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

2017-02-10 17:41:10 +08:00
 Famio
3249 次点击
所在节点    程序员
21 条回复
ArthurKing
2017-02-10 17:50:56 +08:00
static void method(int a,int b){
System.out.println("a=100,b=200");
//throw new NullPointerException();
System.exit(0);
}
finalspeed
2017-02-10 17:54:05 +08:00
楼上的 66666....
kaka8wp
2017-02-10 18:05:27 +08:00
楼上的 66666....
fighter2011
2017-02-10 18:14:41 +08:00
等待其他解答
ininit
2017-02-10 18:19:40 +08:00
楼上的 666
qiayue
2017-02-10 18:21:52 +08:00
@ArthurKing exit 哈哈哈
bianhua
2017-02-10 18:23:00 +08:00
跟你们说吧,只有 1 楼的答案是对的,因为后面那两个它么是的 println (笑哭
ArthurKing
2017-02-10 18:29:25 +08:00
@bianhua 不不不,还可以换成 while(true); ( ˙-˙ )
logbang
2017-02-10 18:32:38 +08:00
楼上的 66666....
Famio
2017-02-10 20:48:33 +08:00
@bianhua 哈哈哈,大兄弟是的。
jasontse
2017-02-10 20:55:46 +08:00
套路。。。
haozibi
2017-02-10 21:00:20 +08:00
1 楼真是简单粗暴
vh2h
2017-02-10 21:08:33 +08:00
自古一楼出奇迹,看来没错啊!膜拜一楼。
aitaii
2017-02-10 22:11:43 +08:00
正常的话是 a
b
aristotll
2017-02-10 23:31:57 +08:00
第二种方法是啥 第一种我也想到了...
virusdefender
2017-02-10 23:50:20 +08:00
valkyrja
2017-02-10 23:52:19 +08:00
似乎可以覆盖 system.out.println 然后 replace?
padeoe
2017-02-11 00:06:19 +08:00
长知识,帮补代码:
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-02-11 00:06:45 +08:00
在 method 中打印结果后,将 stdout 重定向到 stderr
zhilincom
2017-02-11 04:56:42 +08:00
@padeoe 应该是 super.print(s.equals("a=10") ? "a=100," : "b=200");

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

https://www.v2ex.com/t/339610

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

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

© 2021 V2EX