我是初学者,求赐教!
比如谜底是9,第一次猜个8提示低了,第二次猜个10提示高了,第三次还猜8就没提示重复输入。可比如我第一次猜个8提示低了,第二次还猜8就提示重复输入了,这是为什么???
import javax.swing.JOptionPane;
public class CaiShu{
public static void main(String [] args){
int[] yiCaiGuo = new int[4];
int midi = (int)(System.currentTimeMillis()%21);
int shifoucaizhong = 0;
int cishu=0;
for (int i=0;i<4;i++){
String caishu = JOptionPane.showInputDialog(null,"请随机猜一个0~20之间的整数,只有4次机会噢!"+midi);
int shu=Integer.parseInt(caishu);
if(yiCaiGuo[cishu] == shu){
JOptionPane.showMessageDialog (null,"无语,怎么重复输入错的呀!");
i--;
}
if(shu>20 || shu <0){
JOptionPane.showMessageDialog (null,"输的数超出范围啦!");
i--;
}
if(shu == midi){
JOptionPane.showMessageDialog (null,"恭喜你,猜对了!");
shifoucaizhong = 1;
break;
}
if(shu > midi){
JOptionPane.showMessageDialog (null,"高了噢!还有"+(3-i)+"次机会!");
yiCaiGuo[cishu] = shu;
}
if(shu < midi){
JOptionPane.showMessageDialog (null,"低了噢!还有"+(3-i)+"次机会!"); yiCaiGuo[cishu] = shu;
}
}
if(shifoucaizhong==0)
JOptionPane.showMessageDialog (null,"智商也忒低了吧!游戏失败!不就是"+midi+"嘛!");}
}
比如谜底是9,第一次猜个8提示低了,第二次猜个10提示高了,第三次还猜8就没提示重复输入。可比如我第一次猜个8提示低了,第二次还猜8就提示重复输入了,这是为什么???
import javax.swing.JOptionPane;
public class CaiShu{
public static void main(String [] args){
int[] yiCaiGuo = new int[4];
int midi = (int)(System.currentTimeMillis()%21);
int shifoucaizhong = 0;
int cishu=0;
for (int i=0;i<4;i++){
String caishu = JOptionPane.showInputDialog(null,"请随机猜一个0~20之间的整数,只有4次机会噢!"+midi);
int shu=Integer.parseInt(caishu);
if(yiCaiGuo[cishu] == shu){
JOptionPane.showMessageDialog (null,"无语,怎么重复输入错的呀!");
i--;
}
if(shu>20 || shu <0){
JOptionPane.showMessageDialog (null,"输的数超出范围啦!");
i--;
}
if(shu == midi){
JOptionPane.showMessageDialog (null,"恭喜你,猜对了!");
shifoucaizhong = 1;
break;
}
if(shu > midi){
JOptionPane.showMessageDialog (null,"高了噢!还有"+(3-i)+"次机会!");
yiCaiGuo[cishu] = shu;
}
if(shu < midi){
JOptionPane.showMessageDialog (null,"低了噢!还有"+(3-i)+"次机会!"); yiCaiGuo[cishu] = shu;
}
}
if(shifoucaizhong==0)
JOptionPane.showMessageDialog (null,"智商也忒低了吧!游戏失败!不就是"+midi+"嘛!");}
}