import java.util.*;

public class GN {
public static void main(String arg[]) {
int a = ;// 数字标记
int b = ;// 位置标记
int time = ;// 次数
int rdn[] = new int[];
Random rd = new Random(); do {
rdn[] = rd.nextInt();
rdn[] = rd.nextInt();
rdn[] = rd.nextInt();
rdn[] = rd.nextInt();// 生成四个随机数字。
if (rdn[] == || rdn[] == rdn[] || rdn[] == rdn[]
|| rdn[] == rdn[] || rdn[] == rdn[] || rdn[] == rdn[]
|| rdn[] == rdn[] || rdn[] == rdn[] || rdn[] == rdn[]
|| rdn[] == rdn[])
continue;
else
break;
} while (true); do {
System.out.println("请输入您所猜的数字:");
Scanner s = new Scanner(System.in);
int n = s.nextInt();
String x = String.valueOf(n);
if (n == )
System.out.println(rdn[] + "" + rdn[] + "" + rdn[] + ""
+ rdn[]);
int num[] = new int[];
num[] = n / ;
num[] = n / % ;
num[] = n % / ;
num[] = n % ;// 处理键入的数字
if (num[] == ) {
System.out.println("输入的数字不能以零开头,请重新输入。");
} else if (x.length() > || x.length() <= )
System.out.println("输入的数字不符合要求,请重新输入。");
else if (x.length() == ) {
time++;
a = ;
b = ;
for (int i = ; i <= ; i++) {
for (int j = ; j <= ; j++) {
if (num[i] == rdn[j])
if (i == j)
b++;
else
a++; }
}
if (b != )
System.out.println("数字相同而位置不同有 " + a + " 个,位置和数字都相同有 " + b
+ " 个");
if (b != && time > )
System.out.println("你个笨蛋,都猜" + time + "次了,还猜不对!");
}
if (b == ) {
System.out.println("恭喜你,猜对了!一共猜了" + time + "次。");
break;
}
} while (true); } }

最新文章

  1. 2.快速部署MySQL主从复制
  2. 【webGL】threejs常用的api
  3. ORA-32004: obsolete and/or deprecated parameter(s) specified
  4. 解决li在ie,firefox中行高不一致问题
  5. Layout Resource官方教程(1)简介
  6. 多次读取请求request里数据
  7. opengl 函数
  8. Exception testing
  9. 常用的CSS属性
  10. Python购物车的实现课程
  11. hadoop启动守护进程报JAVA_HOME is not set and could not be found
  12. 项目中Spring注入报错小结
  13. 存读Blob Oracle
  14. 兔子与樱花[HEOI2015]
  15. 使用PHP画统计图的方法
  16. python中type dtype astype 的用法
  17. mongodb数据导入导出
  18. 浏览器与Tomcat交互
  19. python爬虫-基础入门-爬取整个网站《2》
  20. js的原型prototype究竟是什么?

热门文章

  1. libaio.so.1: undefined reference to `__stack_chk_fail@GLIBC_2.4&#39;
  2. C# DataTable转实体 通用方法
  3. Apache+php5
  4. ios的两种界面跳转方式
  5. Linux+Redis实战教程_day03_Redis-set【重点】_有序set(了解)
  6. ios开发之--把秒转换为天时分秒
  7. 安装eclipse,配置tomcat
  8. Java调用MQ队列
  9. Fragment获取Activity,Activity获取Fragment
  10. 偶值得纪念的一天-初学习C#