求猜数字游戏的答案

2024-11-23 05:49:15
推荐回答(1个)
回答1:

import javax.swing.JOptionPane;
public class Text {
public static void main(String[] args) {
int number=(int)(Math.random()*100);
String num;
num=JOptionPane.showInputDialog(null," 请猜计算机输出的数:(0~100)");
int i=Integer.parseInt(num);
while(i!=number)
{
if(i>number)
JOptionPane.showMessageDialog(null,"输入的数值大了");
else
{
JOptionPane.showMessageDialog(null,"输入的数值小了");
}
num=JOptionPane.showInputDialog(null," 请猜计算机输出的数:(0~100)");
i = Integer.parseInt(num);
}
System.out.println("恭喜你猜对了!");
}
}

public static void Main(string[] args)
{
int a = 85;
int v = -1;
for (int i = 0; a != v; i++)
{
Console.WriteLine("请输入一个整数");
v = Convert.ToInt32(Console.ReadLine());
if (a < v)
{
Console.WriteLine("大了");
}
else if (a > v)
{
Console.WriteLine("小了");
}
}
Console.WriteLine("正确");
Console.Read();
}