标签:java ext system.in str public new imp switch dom
package abc;
import java.util.Random;
import java.util.Scanner;
public class caishuyouxi {
public static void main(String[] args){
int m,j=0;
while(j==0)
{
System.out.println("1.开始游戏");
System.out.println("2.退出游戏");
Scanner s1=new Scanner(System.in);
m=s1.nextInt();
switch(m)
{
case 1:
youxi();
break;
case 2:
System.exit(0);
break;
}
}
}
public static void youxi(){
Random rand=new Random();
int n=rand.nextInt(1000);
System.out.println(n);
System.out.println("欢迎进入猜字游戏,您一共有10次机会,请输入您猜想的数字:");
for(int i=0;i<10;i++){
Scanner s=new Scanner(System.in);
int d=s.nextInt();
if(d==n){
System.out.println("恭喜您猜对了!!");
System.out.println("请选择是否继续游戏:");
break;
}
else if(d<n){
System.out.println("您输入的数字小了,请重新输入:剩余次数"+(9-i)); System.out.println("请输入您猜想的数字:");
}
else{
System.out.println("您输入的数字大了,请重新输入:剩余次数"+(9-i)); System.out.println("请输入您猜想的数字:");
}
}
}
}
标签:java ext system.in str public new imp switch dom
原文地址:http://www.cnblogs.com/tianjianli/p/7600572.html