import java.util.Scanner;
class SmallGameDemo
public static void main(String[] args)
{
String username = "admin";
String password = "123456";
w:while (true)
{
Scanner sc = new Scanner(System.in);
System.out.println("请输入密码!");
String name = sc.nextLine();
String psd = sc.nextLine();
if (username.equals(name) && password.equals(psd))
{
while (true)
{
Scanner sc1 = new Scanner(System.in);
System.out.println("欢迎进入黑马游戏厅!");
System.out.println("下面我们来玩个游戏:");
System.out.println("请您输入:");
System.out.println("选择1:偶数游戏");
System.out.println("选择2:素数游戏");
System.out.println("选择3:图形游戏");
System.out.println("选择4:惊喜!");
System.out.println("选择5: 退出!");
int choose = sc1.nextInt();
switch (choose)
{
case 1:
while(true)
{
System.out.println("请输入两个整数:你可以得到两者之间的偶数的和!");
int num1 = sc.nextInt();
int num2 = sc.nextInt();
if(num1>num2)
{
System.out.println("输入有错!");
continue;
}
int sum = 0;
for (int x=num1;x<=num2 ;x++ )
{
if (x%2==0)
{
sum +=x;
}
}
System.out.println("sum="+sum);
break;
}
System.out.println("..................");
break;
case 2:
System.out.println("请输入一个正数, 你可以得0到这个数之间有多少素数");
int num1 = sc.nextInt();
int count =0;
for (int x=1;x<=num1 ;x++ )
{
int y = 2;
while (y<x)
{
if (x%y==0)
{
break;
}
y++;
}
if(x==y)
count++;
}
System.out.println("素数共有"+count+"个!");
System.out.println("..................");
break;
case 3:
System.out.println("让用户输入一个1到10的整数n,正三角星星图形");
int num3 = sc.nextInt();
for (int x=0;x<num3 ;x++ )
{
for (int y=0;y<=x ;y++ )
{
System.out.print("*");
}
System.out.println();
}
System.out.println("..................");
break;
case 4:
for (int x=1;x<=9 ;x++ )
{
for (int y=1;y<=x ;y++ )
{
System.out.print(y+"*"+x+"="+y*x+"\t");
}
System.out.println();
}
System.out.println("..................");
break;
case 5:
break w;
default:
System.out.println("请重新输入选项:");
}
}
}
else
System.out.println("密码错误!");
}
}
}
|
|