当前位置: 首页 > 科技观察

有趣的!各种编程语言实现2+2=5

时间:2023-03-17 23:18:21 科技观察

今天在stackexchange上看到一篇很有意思的帖子,讲的是各种编程语言如何实现2+2=5。2+2怎么会等于5??一开始我也很疑惑,但是看了下面各种编程语言实现的方法,我震惊了,让我相信人类真的是不可思议的生物。1、JAVA导入java.lang.reflect.Field;publicclassMain{publicstaticvoidmain(String[]args)throwsException{Classcache=Integer.class.getDeclaredClasses()[0];Fieldc=cache.getDeclaredField("缓存");c.setAccessible(true);整数[]数组=(整数[])c.get(缓存);数组[132]=数组[133];System.out.printf("%d",2+2);}}输出:52、Cintmain(){char__func_version__[]=“5″;//Forsourcecontrolcharb[]=”2″,a=2;printf(“%d+%s=%s\n”,a,b,a+b);返回0;}3、C(Linux,gcc4.7.3)#includeintmain(void){inta=3,b=2;printf(“%d+%d=%d”,–a,b,a+b);}4、Haskellλ>let2+2=5in2+255、BBCBASICMODE6VDU23,52,254,192,252,6,6,198,124,0PRINTPRINT“2+2=”;2+2PRINT“2+3=”;2+36、Python>>>patch='\x312\x2D7'>>>importctypes;ctypes.c_int8.from_address(id(len(patch))+8).value=eval(patch)>>>2+257、JavaScriptg=function(){H=3returnH+H}f=function(){Η=2returnH+H}//3+3=6alert(g())//2+2=5alert(f())8,Bash9,PHPecho'2+2='.(2+2===4?4:2+2===5?5:'不知道');10,Perl#Genericincludesusestrict;使用警告;使用5.010;使用Acme::NewMath;#Ok,timetobegintherealprogram.if(2+2==5){say5;}else{说“不知道……”;}11、C#staticvoidMain(string[]args){varx=2;变化=2;如果(1==0);{++x;}安慰。写行(x+y);}12、C++#includeclassInt{public:Int(constint&a):integ(a){}friendsstd::ostream&operator<<(std::ostream&oss,constInt&rhs){returnoss<

最新推荐
猜你喜欢