Java Quiz(一)
?????? 我准备发一些Java的小Quiz,这些题目看似比较简单,但如果一不小心,就会得出错误的结论,大家小心咯。
?????? 如果你有什么意见或者建议,请留言或者加我的QQ:472429029,验证信息写Java,javaeye什么的都行。
?????? 一。请问下面的代码的运行结果是?
?
/*** created on 2009-4-13* Author softkid*/package cn.softkid;public class MulOrAdd { public static void main(String[] args) { int x=5,y=5; x *= 5+2; y = y*5+2; System.out.println("Value of X is : "+x); System.out.println("Value of Y is : "+y); }}?
怎么样?简单吧!请留言给出你的结果吧!然后编译运行试试,看运行生成的结果是否和你想的一样?
?
?
???? 二。请问下面的代码的运行结果是?
?
/*** created on 2009-4-13* Author softkid*/package cn.softkid;public class MyDouble {public static void main(String[] args) { for(double d = 0.0; d != 1.0; d = d + 0.1){ System.out.println("Tesging..."); } }}?
两道题目下来,你是否觉得我的题目很幼稚呢?如果有兴趣,请继续吧!
?
三。下面一个是关于循环的,请问运行的结果是?
?
/*** created on 2009-4-13* Author softkid*/package cn.softkid;public class MyLoop { public static void main(String[] args) { for(int i=0;i<10;i++){ for(i=0;i<5;i++){ System.out.println("Testing"); } } }}?这一个应该没什么问题?但如果被前面的搞迷糊了,那就不一定了!
?
四。接下来扯到Integer和String了,请问下面代码运行的结果是?
?
/** * created on 2009-4-13 * Author softkid */package cn.softkid;public class Equality {public static void main(String args[]) {Integer first = 100;Integer second = 100;String str1 = "abc";String str2 = "abc";String str3 = new String("abc");String str4 = new String("abc");if (first == second)System.out.println("first == second");elseSystem.out.println("first != second");if (str1 == str2)System.out.println("str1 == str2");elseSystem.out.println("str1 != str2");if (str1 .equals(str3))System.out.println("str1 equals str3");elseSystem.out.println("str1 not equals str3");if (str3 == str4)System.out.println("str3 == str4");elseSystem.out.println("str3 != str4");}}?
这一次就到这里吧,下次再继续!
1 楼 wthwth 2009-04-13 1