A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

import java.util.Scanner;
class TestOne {
        public static void main(String[] args) { //这个是main函数,是程序的主入口,代码的执行,是从这里开始的。
                /*
                        需求:综合小案例
                                        首先进入到游戏选择界面,根据用户输入的数字玩儿对应的游戏                                               
                                                游戏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("Game1:输入一个数字,我给你打印对应的乘法表");
                System.out.println("Game2:输入两个数字,我给你计算出这两个数字间的所有整数和");
                System.out.println("Game3:输入两个数字,有意想不到的惊喜哟!!"); //你来交换着两个数字的值
                System.out.println("Game4:输入两个数字,我能猜到你心里在想什么!");   //正三角形*图
                System.out.println("Game5:输入两个数字,你来计算着两个数字间的奇数有多少个");
                System.out.println("Game6:我说咱俩心有灵犀你信吗?不信你输入下你最喜欢吃的水果"); //
        }
        public static void game1(){
                Scanner sc = new Scanner(System.in);
                System.out.println("请输入一个数字,我来为您创建对应的乘法表哦亲∧_∧:");
                int num = sc.nextInt();
                for (int i = 1;i <= num ;i++ ) {
                        for(int j = 1;j <= i;j++) {
                                System.out.print(j+"*"+i+"="+j*i+"        ");                       
                        }
                        System.out.println();
                        System.out.println("亲,您还满意吗?嘻嘻∧ _ ∧");
                }

        }
        public static void game2(){
                Scanner sc = new Scanner(System.in);
                System.out.println("请输入第一个数:");
                int a = sc.nextInt();
                System.out.println("请输入第二个数:");
                int b = sc. nextInt();
        int sum = 0;
                if(a < b) {
                        for (int x = a;x <= b ;x++ ) {
                                sum += x;       
                        }
                        System.out.println("sum ="+ sum);
                }else {
                        for (int x = b;x <= a ;x++ ) {
                                sum += x;       
                        }
                        System.out.println("sum ="+ sum);       
                }
        }
        public static void game3(){
                Scanner sc = new Scanner(System.in);
                System.out.println("俺来给您服务喽!你想让a=:");
        int yi = sc.nextInt();
                System.out.println("你想让b=:");
                int er = sc.nextInt();
                yi = yi ^ er;
                er = yi ^ er;
                yi = yi ^ er;
                System.out.println("a ="+yi+",b ="+er);
               

        }
        public static void game4(){
                Scanner sc = new Scanner(System.in);
                System.out.println("请输入行数:");
                int row = sc.nextInt();
                System.out.println("请输入列数:");
                int line = sc.nextInt();
                for (int x = 1;x <= row ;x++ ) {
                        for(int y = x;y <= line-1;y++) {
                                System.out.print(" ");
                        }
                        for(int z = 1;z <= x;z++) {
                                System.out.print("* ");                       
                        }
                        System.out.println();
                }
        }
        public static void game5(){
                Scanner sc = new Scanner(System.in);
                System.out.println("请输入第一个数:");
                int a = sc.nextInt();
                System.out.println("请输入第二个数:");
                int b = sc.nextInt();
                int count = 0;
                if (a > b) {
                        for (int x = b;x <= a ; x++) {
                                if (x % 2 != 0) {
                                        count += 1;
                                }
                        }
                }else if (a < b) {
                         for (int x =a; x <= b;x++ ) {
                                 if (x % 2 != 0) {
                                         count += 1;
                                 }
                         }
                }else {
                        System.out.println("你是个逗比吗?为什么输入俩个一样的数?");
                }
                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 );
        }
}

3 个回复

正序浏览
这个可以有
回复 使用道具 举报
这个,很嗨,很嗨,,,也很赞
回复 使用道具 举报
可以的,学习真的需要兴趣
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马