import java.util.Scanner; 
class TestOne2 { 
        public static void main(String[] args) { 
                /* 
                        需求:综合小案例 
                                        首先进入到游戏选择界面,根据用户输入的数字玩儿对应的游戏                                                 
                                                游戏1:让用户输入一个数字,你来打印对应的乘法表 
                                                游戏2:让用户输入两个数字,你来计算出这两个数字间的所有整数和 
                                                游戏3:让用户输入两个数字,你来交换着两个数字的值 
                                                游戏4:让用户输入两个数字,你根据这两个数字来打印一个对应行列的正三角形*图 
                                                     * 
                                                    * * 
                                                   * * * 
                                                  * * * * 
                                                 * * * * * 
                                                游戏5:让用户输入两个数字,你来计算着两个数字间的奇数有多少个。 
                                                游戏6:我说咱俩心有灵犀你信吗?不信你输入下你最喜欢吃的水果 
                                 
                */ 
                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("请输入你想打印的乘法表的数值:"); 
                int a = sc.nextInt(); 
                for (int x=1; x<=a; x++) { 
                        for (int y=1; y<=x; y++) { 
                                System.out.print(y+"*"+x+"="+y*x+"\t"); 
                        } 
                        System.out.println(); 
                } 
 
        } 
        public static void game2(){ 
                Scanner sc = new Scanner(System.in); 
                System.out.println("请输入两个数值:"); 
                int a2 = sc.nextInt(); 
                int b2 = sc.nextInt(); 
                int sum = 0; 
                if (b2>a2) { 
                        for (int x=a2; x<=b2; x++) { 
                                sum+=x; 
                        } 
                }else{ 
                        for (int x=b2; x<=a2; x++) { 
                                sum+=x; 
                        } 
                } 
                        System.out.println("sum="+sum); 
        } 
        public static void game3(){ 
                Scanner sc = new Scanner(System.in); 
                System.out.println("请输入两个数值:"); 
                int a3 = sc.nextInt(); 
                int b3 = sc.nextInt(); 
                a3 = a3 ^ b3; 
                b3 = a3 ^ b3; 
                a3 = a3 ^ b3; 
                System.out.println("a3="+a3+",b3="+b3); 
        } 
        public static void game4(){ 
                Scanner sc = new Scanner(System.in); 
                System.out.println("请输入两个数值:"); 
                int a4 = sc.nextInt(); 
                int b4 = sc.nextInt(); 
                for (int x=0;x<a4 ;x++ ){ 
                        for (int y=x+1;y<b4 ;y++ ){ 
                                System.out.print(" "); 
                        } 
                        for (int z=0;z<=x ;z++ ){ 
                                System.out.print("* "); 
                        } 
                        System.out.println(); 
                } 
        } 
        public static void game5(){ 
                Scanner sc = new Scanner(System.in); 
                System.out.println("请输入两个数值:"); 
                int a5 = sc.nextInt(); 
                int b5 = sc.nextInt(); 
                int count = 0; 
                if (a5<b5) { 
                        for (int x=a5; x<=b5; x++) { 
                                if (x%2!=0) { 
                                        count++; 
                                } 
                        } 
                }else{ 
                        for (int x=b5; x<=a5; x++) { 
                                if (x%2!=0) { 
                                        count++; 
                                } 
                        } 
                } 
                System.out.println(count); 
        } 
        public static void game6(){ 
                Scanner sc = new Scanner(System.in); 
                System.out.println("请输入你最喜欢吃的水果"); 
                String fruit = sc.next(); 
                System.out.println("美女,这么巧啊,我也喜欢吃" + fruit ); 
        } 
} 
 
 |   
        
 
    
    
    
     
 
 |