作者sul32k7x87 (Larry)
看板java
标题[问题] if
时间Mon Nov 16 19:34:21 2009
class Test{
public static void main(String [] args){
boolean b=false;
if(b=true)
System.out.println("欢迎光临");
else
System.out.println("谢谢惠顾");
}
}
这是课本题目
问说上面那段程式码印出来会是甚麽
答案是印出 欢迎光临
我不大能理解
b不是false吗
这样进去跑if的话 应该是执行else的System.out.println("谢谢惠顾");不是吗
怎麽会印出欢迎光临呢
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 61.63.114.33
1F:→ chrisQQ:因为 b=true 先执行了, 如果你要判断的话要改成 == 11/16 19:36
2F:→ sul32k7x87:原来如此 我一直以为IF里面只能有判断式= = 11/16 19:38
3F:→ qrtt1:这应该不能通过 compiler 的考验吧 11/16 21:40
4F:→ remmurds:If a picture paints a thousand words, then why can't 11/16 21:58
5F:→ remmurds:I paint you~ 我来乱的= =" 11/16 21:59
6F:→ sul32k7x87:qrtt1大 其实我也是这麽想 可是题目是这样出XDD 11/16 22:10
7F:→ sbrhsieh:为什麽通不过 compiler 的考验? 11/16 22:24
8F:→ qrtt1:因为我看错了XD 11/16 23:04