【发布时间】:2015-02-02 00:56:09
【问题描述】:
所以下面的代码:
private void pickNext()
{
last = next;
next = (int)(Math.random() * 9 + 1);
System.out.print(""+last + next);
while(last == next)
{
next = (int)(Math.random() * 9 + 1);
}
}
public boolean guessHigh()
{
pickNext();
return next > last;
}
public boolean guessLow()
{
pickNext();
return next < last;
}
基本上说两个整数(已经实例化并且已经定义了next)next 和last 被更改,以便last 是next,然后next 是随机生成的,因此它不是以前的数字。然后guesslow和guesshigh返回如果next>last或next我的问题是它返回什么?它返回真还是假?或者像一个数字? 在我的代码的另一部分:
public void update(boolean arg) //arg 为真表示玩家猜对了 {
if()
{
//random other code
}
else
{
//other code
}
我将如何编写 if 语句,以便如果guessLow 或guessHigh 为真则执行此操作,否则执行此操作? 非常感谢您的帮助
【问题讨论】: