#include<stdio.h>#include<stdlib.h>int main() int s, a; int f = 1;while (f) system("cls");//DOS清屏命令 printf("操作说明:\n\t输入1继续游戏,0退出游戏,-1直接显示本次结果\n\n"); s = rand() % 1000;//生成随机数0-1000之内 printf("请输入您所猜的数字(0-1000) \n"); scanf("%d", &a);while (1) if (a == s) printf("恭喜您猜测成功!\n"); break; }else if (a > s) printf("高了!请再次输入:"); scanf("%d", &a); }else if (a< s) printf("低了!请再次输入:"); scanf("%d", &a); }if (a == -1) printf("%d", s); break; } } printf("提示:\n\t1.重新开始游戏,0.退出游戏:\n请输入:"); scanf("%d", &f); } return (0);}
8,猜数字游戏01000之间用JAVA编程
这简单,代码如下,这是我用记事本写的,没运行过可能有点问题,你修改下就可以了,创建个类以Number 命名,然后直接复制粘贴就可以了。希望能帮到你!import java.util.Scanner;public class number int i = 0; int random = (int) (Math.random() * 1000); System.out.println("我心里有一个0到1000之间的整数,你猜是什么?"); for (i = 0; i < 20; i++) Scanner input = new Scanner(System.in); int f = input.nextInt(); if(f>random) System.out.println("大了点,再猜!"); } else if (f < random ) System.out.println("小了点,再试试!"); } else if (f == random && i == 1) System.out.println("猜对了!\n"+"你太有才了!"); } else if (f == random && i >= 2 && i <= 6) System.out.println("猜对了!\n"+"这么快就猜出来了,很聪明!"); } else if (f == random && i >= 7) System.out.println("猜对了!\n"+"猜了半天才猜出来,老大,你尚需努力啊!"); System.out.println("你要继续吗?(yes / no)"); answer=input.next();} } while(answer.equals("yes")); } }}import java.*; import java.util.scanner; public class test { /** * @param args */ public static void main(string[] args) { // todo auto-generated method stub system.out.print("请输入一个0-1000的整数:"); int counter; int number=(int)(math.random()*1000+1); int guess; boolean iscorrect=false; scanner input = new scanner(system.in); for(counter=1;counter<10;counter++){ guess=input.nextint(); if(guess==number){ iscorrect=true; break; }else if(guess>number){ system.out.println("大了点,再来!"); }else if(guess7){ system.out.println("还不错!"); }else{ system.out.println("失败"); } } } }