为了账号安全,请及时绑定邮箱和手机立即绑定

请问一下这个程序有什么问题???

请问一下这个程序有什么问题???

MineDearm 2017-08-12 23:41:53
public class caiziyouxi { public static void main(String[] args) throws InterruptedException { int n = 0;     int m = 0;     int c = 0; int x = (int)(Math.random()*25); int y = (int)(Math.random()*25); /*定义要猜的数字的范围*/         if (x > y) {System.out.println("要猜的数字在   "+y+"~"+x+" 之间");                      n = y+(int)(Math.random()*x);                      m = y+(int)(Math.random()*x);                      c = y+(int)(Math.random()*x);}         else if (y > x) {System.out.println("要猜的数字在   "+x+"~"+y+" 之间");                          n = x+(int)(Math.random()*y);                          m = x+(int)(Math.random()*y);                          c = x+(int)(Math.random()*y);}         else {x = (int)(Math.random()*100);         if (x > y) {System.out.println("要猜的数字在   "+y+"~"+x+" 之间");                     n = y+(int)(Math.random()*x);                     m = y+(int)(Math.random()*x);                     c = y+(int)(Math.random()*x);}         if (y > x) {System.out.println("要猜的数字在   "+x+"~"+y+" 之间");                     n = x+(int)(Math.random()*y);                     m = x+(int)(Math.random()*y);                     c = x+(int)(Math.random()*y);}         }             /*输出要猜的数字的范围及定义要猜的数字*/Thread.sleep(2000);         System.out.println("现在开始选定玩家");            int z = (int)(Math.random()*4);/*确定玩家数量为5*/         String A = new String();         if (z == 0) {A = "Mary";}         else if (z == 1) {A = "Tom";}         else if (z == 2) {A = "Steve";}         else if (z == 3) {A = "Barry";}         else {A = "Tony";}         Thread.sleep(5000);/*程序延迟5S*/         System.out.println("第一位玩家是:"+A);/*创建玩家A*/         if (z < 4) {z = z + 1;}         else {z = z - 1;}         String B = new String();         if (z == 0) {B = "Mary";}         else if (z == 1) {B = "Tom";}         else if (z == 2) {B = "Steve";}         else if (z == 3) {B = "Barry";}         else {B = "Tony";}         Thread.sleep(3000);/*程序延迟3S*/         System.out.println("第二位玩家是:"+B);/*创建玩家B*/Thread.sleep(1000);         System.out.println("玩家开始猜数......");         Thread.sleep(10000);/*程序延迟10S*/         if (m == n) {System.out.println("恭喜选手"+A+"猜对了!!!");}         else if (c == n) {System.out.println("恭喜选手"+B+"猜对了!!!");}         else {System.out.println("很可惜两位玩家都猜错了,请重新开始猜数。");               while (m > n|m < n|c > n|c < n){                m++;c--;                System.out.println("玩家开始猜数......");                   Thread.sleep(5000);/*程序延迟5S*/                   if (m == n) {System.out.println("恭喜选手"+A+"猜对了!!!");}                   else if (c == n) {System.out.println("恭喜选手"+B+"猜对了!!!");}                   else {System.out.println("很可惜两位玩家都猜错了,请重新开始猜数。");}                   }               }                  } } 为啥每次运行n和x、y的数都对不上???
查看完整描述

1 回答

已采纳
?
__innocence

TA贡献313条经验 获得超208个赞

没看你的逻辑,但是我觉得是这里错了:

while (m > n|m < n|c > n|c < n)

如果表示或,应该是

while (m > n || m < n || c > n || c < n)

一个竖线表示位运算,两个竖线表示或

查看完整回答
1 反对 回复 2017-08-12
  • MineDearm
    MineDearm
    o,这个还真没发现,逻辑的问题我发现了了,m+(int)(Math.rondam()*x是随机取m到m+x的值,我当成m到x了。
  • 1 回答
  • 1 关注
  • 1142 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信