*/
public static void main(String[] args) { //这个是main函数,是程序的主入口,代码的执行,是从这里开始的。
reTent();
}
public static void reTent() {
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;
default :
System.out.println("输入错误");
reTent();
}
}
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("请输入一个数字,我给你打印对应的乘法表");
int x = sc.nextInt();
for(int i = 1;i <= x; i++){
for(int j = 1; j <= i ;j++) {
System.out.print("\t"+j+"*"+i+" = "+j*i+" ");
}
System.out.println();
}
}
public static void game2(){
Scanner sc = new Scanner(System.in);
System.out.println("请输入两个数字,我给你求这两个数字之间所有整数和");
int x = sc.nextInt();
int y = sc.nextInt();
int sum = 0;
if(x > y) {
x = x ^ y;
y = x ^ y;
x = x ^ y;
}
if(y - x == 1) {
System.out.println("输入的两数为相邻的数字,两者之间没有整数");
return;
}
for(int i = x+1; i < y; i++) {
sum += i;
}
System.out.println(x+"与"+y+"之间的整数和为: "+sum);
}
public static void game3(){
Scanner sc = new Scanner(System.in);
System.out.println("请输入两个整数");
int x = sc.nextInt();
int y = sc.nextInt();
x = x ^ y;
y = x ^ y;
x = x ^ y;
System.out.println("第一个数的值"+x+"第二个数的值"+y);
}
public static void game4(){
System.out.println("请输入你想输入的两个数字");
Scanner sc = new Scanner(System.in);
int x = sc.nextInt();
int y = sc.nextInt();
for(int i = 1; i <= x; i++ ){
for(int j = 1; j <= i;j++) {
System.out.print("*"+" ");
}
System.out.println();
}
for(int i = 1; i <= y; i++ ){
for(int j = 0; j <= y-i;j++) {
System.out.print(" "+" ");
}
System.out.println();
}
}
public static void game5(){
System.out.println("输入两个数字,你来计算着输入两个数字,你来计算着两个数字间的奇数有多少个");
Scanner sc = new Scanner(System.in);
int x = sc.nextInt();
int y = sc.nextInt();
int count = 0;
if(x > y){
x = x ^ y;
y = x ^ y;
x = x ^ y;
}