一个小游戏。。哈哈
import java.util.Scanner;
public class Area
{
public static void main(String[] args)
{
int a=(int)(Math.random()*100);//随机函数
int answer = 110;
do
{
System.out.print("请猜一个数:");
Scanner input=new Scanner(System.in);
answer=input.nextInt();
if(a==answer)
System.out.print("您终于猜对了");
else if(a>answer)
System.out.print("您猜的数字偏低!\n");
else if(a<answer)
System.out.print("您猜的数字偏高!\n");
}while(a!=answer);
}
}
转载于:https://blog.51cto.com/14233078/2365630