先按照顺时针方向从1开始依此数数。若是数到7的倍数或者含有7这个数,则调转方向接着

作者在 2010-05-17 10:15:00 发布以下内容
//酒吧里,一桌人(≥10)围在一起行酒令。酒令如下:先按
 //照顺时针方向从1开始依此数数。若是数到7的倍数或者含有7
 //这个数,则调转方向接着数。依此类推。请模拟此过程。
 public static void main(String[] args) {
  int m=input();
  if(m<10){//判断如果值小于10抛出异常
   try {
    throw new Exception();
   } catch (Exception e) {
    System.out.println("你输入的数小于10");
    e.printStackTrace();
   }
  }
  List list=new ArrayList();
        for(int i=1;i<m;i++){
         list.add(i);//给每一个一个编号
        }
        boolean current=true;//false为反向true为正向
        int cree=0;//为每个人编号
        int i=1;//为所数的数
        while(true){
         cree=(cree+list.size())%list.size();
         System.out.println(list.get(cree)+"您数的数是"+i);
         if(i%10==7||i%7==0){
          System.out.println("行酒令,"+list.get(cree));
          current=!current;
          cree-=2;
         }
         cree+=1;
         i++;
         try {
    Thread.sleep(100);
   } catch (InterruptedException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
   }
        }
 }
   public static int input(){
    Scanner sc=new Scanner(System.in);
    return sc.nextInt();
   }
}
专业文章 | 阅读 1025 次
文章评论,共0条
游客请输入验证码
浏览275841次