• java第12次作业


    1.编写程序

    package homework;
    import java.util.Random;
    import java.util.Scanner;
    public class menu {
    
        public static void main(String[] args) {
            // TODO Auto-generated method stub
            mainmenu();
    
        }
         public static void mainmenu() {
                Scanner input = new Scanner(System.in);
                System.out.println("****************");
                System.out.println("   1. 登录");
                System.out.println("   2. 注册");
                System.out.println("   3.幸运抽奖");
                System.out.println("   4.看小故事");
                System.out.println("   5.退出系统");
                System.out.println("****************");
                System.out.print("请选择:");
                int i = input.nextInt();
                switch (i) {
                case 1:
                    login();
                    break;
                case 2:
                    register();
                    break;
                case 3:
                    luck();
                    break;
                case 4:
                    story();
                    break;
                case 5:
                    exit();
                    break;
                default:
                    System.out.println("该系统暂未开放其它功能!");
                    break;
    
    
         }
    }
         private static void login() {
                // TODO Auto-generated method stub
                Scanner input = new Scanner(System.in);
                System.out.print("请输入您的用户名:");
                String uname = input.next();
                System.out.print("请输入您的密码:");
                String upwd = input.next();
                if (uname.equals("zj") && upwd.equals("0909")) {
                    System.out.println("登录成功!");
                } else {
                    System.out.println("登录失败");
                }
                returnMain();
         
            }
         
            public static void returnMain() {
                System.out.println("是否返回主菜单?Y/N");
                Scanner input = new Scanner(System.in);
                if (input.next().equalsIgnoreCase("Y")) {
                    mainmenu();
                } else {
                    System.out.println("谢谢使用");
                }
         
            }
         
            public static void register() {
                Scanner input = new Scanner(System.in);
                System.out.print("请输入您的用户名:");
                String uname = input.next();
                System.out.print("请输入您的密码:");
                String upwd = input.next();
                System.out.println("您的账号已注册成功!!!");
                returnMain();
            }
         
            public static void luck() {
                System.out.println("**************************************欢迎来到幸运抽奖界面!*************************************");
                System.out.println(" *******规则为:如果您输入的四位会员卡号的百位等于系统随机数,您将成为我们的幸运会员,否则不是*******");
                Scanner input = new Scanner(System.in);
                int temp = 0;
                for (int i = 0;; i++) {
                    System.out.print("请您输入四位的会员卡号:");
                    int vipcard = input.nextInt();
                    int bai = vipcard % 1000 / 100;
                    temp = bai;
                    if (vipcard < 999 || vipcard > 9999) {
                        System.out.println("您的会员卡号错误,请您重新输入!");
                    } else {
                        break;
                    }
                }
                Random r = new Random();
                int num = r.nextInt(9);
                System.out.println("系统生成的百位随机数为:" + num);
                if (num == temp) {
                    System.out.println("恭喜您,成为我们的幸运会员!");
                } else {
                    System.out.println("很遗憾,感谢您的参与!");
                }
                returnMain();
            }
         
            public static void story() {
                System.out.println("请您输入相应的数字(1-3)观看小故事!");
                for (int i = 0;; i++) {
                    Scanner input = new Scanner(System.in);
                    int num = input.nextInt();
                    switch (num) {
                    case 1:
                        System.out.println("灰姑娘");
                        break;
                    case 2:
                        System.out.println("鼓手");
                        break;
                    case 3:
                        System.out.println("格林童话");
                        break;
                    default:
                        System.out.println("您的输入有错,请重新输入!");
                    }
                    break;
                }
                returnMain();
            }
         
            public static void exit() {
                System.out.println("是否退出该系统?Y/N");
                Scanner input = new Scanner(System.in);
                if (input.next().equalsIgnoreCase("N")) {
                    mainmenu();
                } else {
                    System.out.println("您已退出我们的系统,谢谢使用!");
                }
         
            }
         
        }

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

    package one;
    
    public class jc {
    
    public static int Jc(int n) {
        int cj=1;
        for (int i = 1; i <= n; i++) {
            cj*=i;
        }
        return cj;
    }
    public static void main(String[] args) {
        System.out.println(Jc(7));
    }

    3. 编写一个方法 判断该年份是平年还是闰年

    package one;
    
    public class Year {
        public static void Year(int n) {
            if (n % 4 == 0 && n % 100 != 0 || n % 400 == 0) {
                System.out.println(n + "是闰年");
            } else {
                System.out.println(n + "是平年");
            }
        }
         
        public static void main(String[] args) {
            Year y = new Year();
            Year(2000);
        }
    
    }

  • 相关阅读:
    快速排序
    Java LinkedList
    Java ArrayList
    Java ReentrantLock
    Java Timer
    Java 管道PipedInputStream PipedOutStream PipedReader PipedWriter
    6. Samba服务和防火墙配置笔记
    5. 网络配置与FTP服务笔记
    3.vi 和软件安装
    2 . Linux常见命令
  • 原文地址:https://www.cnblogs.com/zjzj123/p/12793344.html
Copyright © 2020-2023  润新知