java猜数字游戏

import java.util.Scanner;

//导入包

class GuessNum
{
public static void main(String[] args)
{
int num = (int)(Math.random()*100)+1;

//获取随机数
int times=0;
while(times<5)
{
times++;
System.out.println("剩余次数:"+(5-times));
System.out.println("请输入你猜测的数字");
Scanner sc = new Scanner(System.in);
int i = sc.nextInt();
if (num>i)
{
System.out.println("你猜的"+i+"小了");

}
else if(num<i)
{
System.out.println("你猜的"+i+"大了");

}
else
System.out.println("恭喜你猜中了");

}
if(times==5)
System.out.println("你输了");
}
}

上一篇:[转]MPP架构


下一篇:docker官方文档笔记