zoukankan      html  css  js  c++  java
  • 第八周作业

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

    package method;
    
    import java.util.Random;
    import java.util.Scanner;
    
    public class Menu {
        public static void main(String[] args) {
            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("请选择:");
            int a = input.nextInt();
            switch (a) {
            case 1:
                login();
                break;
            case 2:
                register();
                break;
            case 3:
                luck();
                break;
            case 4:
                lookstory();
                break;
            case 5:
                off();
                break;
            default:
                break;
            }
        }
    
        private static void login() {
            Scanner input = new Scanner(System.in);
            System.out.println("输入用户名:");
            String youName = input.next();
            System.out.println("输入密码:");
            String password = input.next();
            if (youName.equals("qsf") && password.equals("123321")) {
                System.out.println("登录成功");
            } else {
                System.out.println("登录失败");
            }
            returnMain();
        }
    
        private static void register() {
            Scanner input = new Scanner(System.in);
            System.out.println("输入昵称:");
            String jName = input.next();
            System.out.println("输入密码:");
            String password = input.next();
            System.out.println("注册成功");
            returnMain();
        }
    
        private static void luck() {
            Scanner input = new Scanner(System.in);
            System.out.println("请输入五位会员卡号:");
            int b = input.nextInt();
            Random sj = new Random();
            int x = sj.nextInt(10);
            if (b / 100 % 10 == x) {
                System.out.println("恭喜您中奖了");
            } else {
                System.out.println("谢谢参与");
            }
            returnMain();
        }
    
        private static void lookstory() {
            Scanner input = new Scanner(System.in);
            System.out.println("请选择想看的故事:");
            System.out.println("1.喜羊羊与灰太狼");
            System.out.println("2.惊雷");
            System.out.println("3.小兵张嘎");
            int c = input.nextInt();
            switch (c) {
            case 1:
                System.out.println("一群小羊与一只灰狼展开的故事。");
                break;
            case 2:
                System.out.println("是最近很火的一首喊麦歌曲,原创演唱者:MC六道。");
                break;
            case 3:
                System.out.println("讲述了小嘎子在老钟叔等的引导下,成为一名八路战士的过程。");
                break;
            default:
                break;
            }
            returnMain();
        }
    
        public static void off() {
            System.out.println("已经退出系统");
        }
    
        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("谢谢使用");
            }
        }
    }

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

    package Svd;
    
    import java.util.*;
    
    public class bbt {
    
        public static void main(String[] args) {
            // TODO Auto-generated method stub
            int a = 1;
            Scanner sc = new Scanner(System.in);
            System.out.println("请输入一个数:");
            int x = sc.nextInt();
            for (int i = 1; i <= x; i++) {
                a *= i;
            }
            System.out.println(x + "的阶乘为:" + a);
        }
    }

     3.编写一个方法,判断该年份是平年还是闰年。[必做题]

    package Svd;
    
    import java.util.*;
    
    public class bbt {
    
        public static void main(String[] args) {
    
            Scanner input = new Scanner(System.in);
    
            System.out.println("请输入年份:");
            int a = input.nextInt();
            if (a % 4 == 0 && a % 100 != 0 || a % 400 == 0) {
                System.out.println(a + "是闰年");
            } else {
                System.out.println(a + "是平年");
            }
        }
    
    }

  • 相关阅读:
    成长型思维
    Spring Boot 入门详细分析
    我们为什么要学习 Spring Boot
    躲不掉的 lambda 表达式
    Java 并发工具包 | J.U.C
    Java 并发编程整体介绍 | 内含超多干货
    彻底搞懂单例模式如何安全的实现
    atomic 包、synchronized | Java 中线程安全
    AD在更新PCB的时候,每次封装都会改变位置?
    1206封装电容在物料可靠性设计比较低
  • 原文地址:https://www.cnblogs.com/qsf1975747------/p/12797617.html
Copyright © 2011-2022 走看看