import java.util.Scanner;
class YouXi {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("请输入你要玩儿的游戏的编号,游戏如下:");
show();
int num = sc.nextInt();
System.out.println("你选择玩儿的是游戏是Game" + num);
switch (num) {
case 1:
Scanner s1 = new Scanner(System.in);
System.out.println("请输入一个数:");
int num2 = s1.nextInt();
game1(num2);
break;
case 2:
Scanner s2 = new Scanner(System.in);
System.out.println("请输入第一个数:");
int num3 = s2.nextInt();
System.out.println("请输入第二个数:");
int num4 = s2.nextInt();
int x = game2(num3,num4);
System.out.println("两数之间所有整数和为:" + x);
break;
case 3:
Scanner s3 = new Scanner(System.in);
System.out.println("请输入第一个数:");
int num5 = s3.nextInt();
System.out.println("请输入第二个数:");
int num6 = s3.nextInt();
game3(num5,num6);
break;
case 4:
Scanner s4 = new Scanner(System.in);
System.out.println("请输入一个数:");
int num7 = s4.nextInt();
game4(num7);
break;
case 5:
Scanner s5 = new Scanner(System.in);
System.out.println("请输入第一个数:");
int num9 = s5.nextInt();
System.out.println("请输入第二个数:");
int num0 = s5.nextInt();
int a = game5(num9,num0);
System.out.println("两数之间奇数个数为:" + a);
break;
case 6:
game6();
break;
}
}
public static void show(){
System.out.println("\tGame1:输入一个数字,我给你打印对应的乘法表");
System.out.println("\tGame2:输入两个数字,我给你计算出这两个数字间的所有整数和");
System.out.println("\tGame3:输入两个数字,有意想不到的惊喜哟!!"); //来交换着两个数字的值
System.out.println("\tGame4:输入一个数字,我能猜到你心里在想什么!"); //正三角形*图
System.out.println("\tGame5:输入两个数字,你来计算着两个数字间的奇数有多少个");
System.out.println("\tGame6:我说咱俩心有灵犀你信吗?不信你输入下你最喜欢吃的水果"); //
}
public static void game1(int n){
for (int x = 1;x <= n ;x++ ) {
for (int y = 1;y<= x ;y++ ) {
System.out.print(y + "*" + x + "=" + (x*y) + "\t");
}
System.out.println();
}
}
public static int game2(int a,int b){
int sum = 0;
if (a > b) {
a = a ^ b;
b = a ^ b;
a = a ^ b;
}
int x = a;
while (x <= b) {
sum += x;
x++;
}
return sum;
}
public static void game3(int a,int b){
a = a ^ b;
b = a ^ b;
a = a ^ b;
System.out.println("两数将交换位置:");
System.out.println(a);
System.out.println(b);
}
public static void game4(int m){
for (int x = 1;x <= m ;x++) {
for (int z = 1;z <= m-x ;z++){
System.out.print(" ");
}
for (int y = 1;y <= x ;y++){
System.out.print("*");
System.out.print(" ");
}
System.out.println();
}
}
public static int game5(int a,int b){
int count = 0;
if (a > b) {
a = a ^ b;
b = a ^ b;
a = a ^ b;
}
for (int x = a;x <= b ;x++ ) {
if (x % 2 == 1) {
count ++;
}
}
return count;
}
public static void game6(){
Scanner sc = new Scanner(System.in);
System.out.println("请输入你最喜欢吃的水果");
String fruit = sc.next();
System.out.println("美女,这么巧啊,我也喜欢吃" + fruit ); |
|