- 博客(0)
- 资源 (1)
- 收藏
- 关注
基于Java写的猜数字
import java.awt.*;
import javax.swing.JOptionPane;
public class guessNumber {
public static void main(String args[])
{
int guesscount=-1;//用户猜的次数
int count=0;//用户猜的数字
int number=(int)(Math.random()*100);//0-100的随机数
while(number!=count)
{
count=Integer.parseInt(JOptionPane.showInputDialog("guess a number between 0 amd 100"));
if(number>count)
{
JOptionPane.showMessageDialog(null, "too low");
}
if(number<count)
{
JOptionPane.showMessageDialog(null, "too high");
}
guesscount++;
}
JOptionPane.showMessageDialog(null, "you guessed the number -"+count+"-in"+guesscount+"guess !!!");
}
}
2019-03-27
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人