• 第十一次作业


    1.完善menu注册功能,抽奖,看小故事等功能

    package kkk;
    
    import java.util.Random;
    import java.util.Scanner;
    
    public class lll {
    
        public static void main(String[] args) {
            // TODO Auto-generated method stub
                mainMenu();
                
        }
    
        private static void mainMenu() {
            // TODO Auto-generated method stub
            Scanner input = new Scanner(System.in);
            System.out.println("1:登录");
            System.out.println("2:注册");
            System.out.println("3:幸运抽奖");
            System.out.println("4:小故事");
            System.out.println("5:退出系统");
            System.out.println("6:选择");
            int i = input.nextInt();
            switch (i) {
            case 1:
                logIn();
                break;
            case 2:
                register();
                break;
            case 3:
                luck();
                break;
            case 4:
                story();
                break;
            case 5:
                back();
                break;
            default:
                break;
            }
        }
    
        private static void back() {
            // TODO Auto-generated method stub
            System.out.println("再见了,我终于弄完了");
        }
    
        private static void story() {
            // TODO Auto-generated method stub
            Scanner input = new Scanner(System.in);
            System.out.println("1:狼");
            System.out.println("2:蛇");
            System.out.println("3:小猪");
            System.out.println("选择");
             int a = input.nextInt();
             switch (a) {
            case 1:
                wolf();
                break;
            case 2:
                snake();
                break;
            default:
                pig();
                break;
            }
             mainMenu();
        }
    
        
    
        private static void pig() {
            // TODO Auto-generated method stub
            System.out.println("从前,有头猪,我不知道了");
            backMain();
        }
    
        private static void snake() {
            // TODO Auto-generated method stub
            System.out.println("蛇有毒,哈哈啊哈");
            backMain();
        }
    
        private static void wolf() {
            // TODO Auto-generated method stub
            System.out.println("我是一头狼,哈哈啊哈");
            backMain();
        }
    
        private static void luck() {
            // TODO Auto-generated method stub
            Scanner input = new Scanner(System.in);
            System.out.println("输入4个数字");
             int a = input.nextInt();
             Random r = new Random();
             int i = r.nextInt(9);
             int k = r.nextInt(9);
             int q,s;
             q=a/1000;
             s=a%100/10;
             if(q==i&&s==k) {
                System.out.println("幸运顾客,奖1万块");
            }
             else{
                 System.out.println("谢谢惠顾!");
             }
             mainMenu();
        }
    
        private static void register() {
            // TODO Auto-generated method stub
            Scanner input = new Scanner(System.in);
            System.out.println("输入姓名");
            String uname = input.nextInt();
            Scanner input = new Scanner(System.in);
            System.out.println("输入性别");
            char sex= input.nextInt();
            System.out.println("输入年龄");
            int  age= input.nextInt();
            System.out.println("输入密码");
            long a = input.nextInt();
            System.out.println("注册成功");
            mainMenu();
        }
    
        private static void logIn() {
            // TODO Auto-generated method stub
            Scanner input = new Scanner(System.in);
            System.out.println("输入姓名");
            String uname = input.nextInt();
            System.out.println("输入密码");
            String a = input.nextInt();
            if (uname.equals("xxl")&&a.equals(123456)) {
                System.out.println("登录成功");
            }
            else{
                System.out.println("登陆失败");
            }
            backMain();
        }
    
        private static void backMain() {
            // TODO Auto-generated method stub
            Scanner input = new Scanner(System.in);
            System.out.println("是否返回主菜单");
            int i=input.nextInt();
            if (input.next().equalsIgnoreCase("Y")) {
                mainMenu();
            }
            else{
                System.out.println("谢谢使用");
            }
        }
    
    }

    2.编写一个方法,求整数n的阶乘,例如5的阶乘是1*2*3*4*5

    package kkk;
    
    import java.util.Scanner;
    
    public class lll {
    
        public static void main(String[] args) {
            int sum=1;
            Scanner sc = new Scanner(System.in);
            System.out.println("请输入一个整数:");
            int k = sc.nextInt();
            for (int i = 1; i <= k; i++) {
                sum=sum*i;
            }
            System.out.println(k+"的阶乘为:"+sum);
        }
    }
  • 相关阅读:
    [Unity3D]查看与设置游戏帧数FPS
    [Unity3D]关于NaN(Not a Number)的问题
    Unity3D在WebPlayer模式下的异常上报探索
    .net错误处理机制
    .Net 下未捕获异常的处理
    Appstore 提交时错误
    播放器设置 Player Settings
    (转)WebApi发送HTML表单数据:文件上传与多部分MIME
    (转)那些年我们一起清除过的浮动
    AppCan上下拉列表刷新
  • 原文地址:https://www.cnblogs.com/xuwei123456/p/12803600.html
Copyright © 2020-2023  润新知