java的移位运算的一个小问题

kongpinggudaodeai 2012-07-21 11:01:43
public class HomeWork4 {
public static void main(String[] args) {

int schedule = 0x77;
String[] flag = {"星期天","星期一","星期二","星期三","星期四","星期五","星期六"};
Scanner in = new Scanner(System.in);
System.out.print("请输入你要查询的星期: ");
String week;

int shift = 0;
while(true){
week = in.nextLine();

for(shift = 0 ; shift<=6;shift++){
if(week==flag[shift])
break;
}
if(shift>6){
System.out.print("您的输入是错误的,请重新输入:");
}
}

// 下面一步编译不通过。什么原因。该如何解决
int result = (schedule >> shift) & 0x01;
if(1 == result)
System.out.println("有航班!!!");

else
System.out.println("对不起。没有航班!!!!");
}

}
编译时在int result = (schedule >> shift) & 0x01; 这一步报错是什么原因。怎么解决。
...全文
58 1 打赏 收藏 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
MiceRice 2012-07-21
  • 打赏
  • 举报
回复
编译通不过的原因是因为你之前写了个死循环:

while(true) {

而且这个循环里面根本没有 break; 这种跳出循环的语句。
——注意,for循环中的break 只能跳出for循环本身,不能跳出while循环!!


所以编译器认为后续的代码全都不可能被执行到,是“dead code”。

62,620

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧