猜数字游戏(实现按s开始,按q结束)
来源:互联网 发布:商品期货模拟软件 编辑:程序博客网 时间:2024/05/06 16:56
import java.util.Scanner;
import java.util.Random;
public class Game
{
public static void main(String[]args)
{
Scanner sca=new Scanner(System.in);
Random ran=new Random();
System.out.println("游戏开始");
System.out.println("回车开始游戏");
int p=0;
int p1=0;
for(;;)
{
String str=sca.nextLine();
for(int x=1;x<4;x++)
{
System.out.println("请输入数字进行猜测");
int a=sca.nextInt();
int b=ran.nextInt(10)+1;
if(a==b)
{
p++;
System.out.println("猜对了,你猜的数是:"+a);
}
if(a>b)
{
p1++;
System.out.println("猜错了,你猜的数是:"+a+"电脑的数是:"+b+" 偏大");
}
if(a<b)
{
p1++;
System.out.println("猜错了,你猜的数是:"+a+"电脑的数是:"+b+" 偏小");
}
if(x==3)
{
System.out.println("三次游戏结束");
break;
}
if(str.equals("q"))
{
System.out.println("退出程序");
break;
}
}
System.out.println("一共运行了"+(p+p1)+"次"+" ,"+"猜对了:"+p+","+"猜错了:"+p1);
}
}
}
import java.util.Random;
public class Game
{
public static void main(String[]args)
{
Scanner sca=new Scanner(System.in);
Random ran=new Random();
System.out.println("游戏开始");
System.out.println("回车开始游戏");
int p=0;
int p1=0;
for(;;)
{
String str=sca.nextLine();
for(int x=1;x<4;x++)
{
System.out.println("请输入数字进行猜测");
int a=sca.nextInt();
int b=ran.nextInt(10)+1;
if(a==b)
{
p++;
System.out.println("猜对了,你猜的数是:"+a);
}
if(a>b)
{
p1++;
System.out.println("猜错了,你猜的数是:"+a+"电脑的数是:"+b+" 偏大");
}
if(a<b)
{
p1++;
System.out.println("猜错了,你猜的数是:"+a+"电脑的数是:"+b+" 偏小");
}
if(x==3)
{
System.out.println("三次游戏结束");
break;
}
if(str.equals("q"))
{
System.out.println("退出程序");
break;
}
}
System.out.println("一共运行了"+(p+p1)+"次"+" ,"+"猜对了:"+p+","+"猜错了:"+p1);
}
}
}
0 0
- 猜数字游戏(实现按s开始,按q结束)
- 猜数字游戏实现
- 实现猜数字游戏
- 猜数字游戏的实现
- 猜数字游戏的实现
- struts2实现猜数字游戏
- 猜数字游戏的实现
- 随机数实现猜数字游戏
- python实现猜数字游戏
- Go实现猜数字游戏
- vim时按了Ctrl+S的解决办法:Ctrl+Q
- vim Ctrl-S造成窗口僵死,按Ctrl-Q恢复。
- 文曲星中的猜数字游戏 python 实现
- 用java实现的猜数字游戏
- 实现控制台的猜数字游戏。
- 猜数字游戏(简单C#实现)
- UI, 猜数字游戏的实现
- 猜数字游戏(C实现)
- Oracle 无法删除当前已连接的用户
- 学习红黑树
- 函数
- log4j PatternLayout
- log4j日志记录到文件
- 猜数字游戏(实现按s开始,按q结束)
- centOS6.4下Percona-XtraBackup的安装
- QTCreator项目转移到VS项目步骤、中文乱码解决方案
- vs2008编译错误fatal error C1902: 程序数据库管理器不匹配;请检查安装解决
- 图片的多个上传
- 第一个Spring restful 项目-从开发到部署
- sshfs 远程挂在文件系统
- 初学java适配器模式
- 回文的判断