*/
Scanner sc = new Scanner(System.in);
System.out.println("请输入你要玩儿的游戏的编号,游戏如下:");
show();
int num = sc.nextInt();
System.out.println("你选择玩儿的是游戏是Game" + num);
switch (num) {
case 1:
game1();
break;
case 2:
game2();
break;
case 3:
game3();
break;
case 4:
game4();
break;
case 5:
game5();
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(){
Scanner sc = new Scanner(System.in);
System.out.println("请输入一个数字,范围是1-9:");
int x=sc.nextInt();
print(x);
}
public static void print(int x){
for (int a=1;a<=x ; a++) {
for (int b=1;b<=a ;b++ ) {
System.out.print(a+"*"+b+"="+b*a+"\t");
}
System.out.println();
}
}
public static void game2(){
Scanner sc = new Scanner(System.in);
System.out.println("请输入第一个数字:");
int x=sc.nextInt();
System.out.println("请输入第二个数字,大于第一个数字:");
int y=sc.nextInt();
int sum= getsum(x,y);
System.out.println(sum);
}
public static int getsum(int x,int y){
int sum=0;
for (int a= x;a<=y ; a++) {
sum+=a;
}
return sum;
}
public static void game3(){
Scanner sc = new Scanner(System.in);
System.out.println("请输入第一个数字a:");
int x=sc.nextInt();
System.out.println("请输入第二个数字b:");
int y=sc.nextInt();
exchange(x,y);
}
public static void exchange(int x,int y){
int a=x;
int b=y;
a=a^b;
b=a^b;
a=a^b;
System.out.println("a="+a+",b="+b);
}
public static void game4(){
Scanner sc = new Scanner(System.in);
System.out.println("请输入第一个数字:");
int x=sc.nextInt();
System.out.println("请输入第二个数字:");
int y=sc.nextInt();
printxing(x,y);
}
public static void printxing(int x,int y){
for (int a=1;a<=x;a++ ) {
for (int c=1;c<a ; c++) {
System.out.print(" ");
}
for (int b=1;b<=x-a ; b++) {
System.out.print("* ");
}
System.out.println();
}
}
public static void game5(){
Scanner sc = new Scanner(System.in);
System.out.println("请输入第一个数字:");
int x=sc.nextInt();
System.out.println("请输入第二个数字大于第一个数字:");
int y=sc.nextInt();
int count=getcount(x,y);
System.out.println(count);
}
public static int getcount(int x,int y){
int count=0;
for (int a=x;a<=y ;a++ ) {
if (a%2!=0) {
count++;
}
}
return count;
}
public static void game6(){
Scanner sc = new Scanner(System.in);
System.out.println("请输入你最喜欢吃的水果");
String fruit = sc.next();
System.out.println("美女,这么巧啊,我也喜欢吃" + fruit );
}
}