zoukankan      html  css  js  c++  java
  • 4.24作业

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

    package a;

    import java.util.*;

    public class menu {
    public static void main(String[] args) {
    mainMenu();
    }

    public static void mainMenu() {
    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("请选择");
    int i = input.nextInt();
    switch (i) {
    case 1:
    login();
    break;
    case 2:
    zhuce();
    break;
    case 3:
    choujiang();
    break;
    case 4:
    story();
    break;
    case 5:
    tuichu();
    break;

    }
    }

    public static void login() {
    // TODO Auto-generated method stub
    Scanner input = new Scanner(System.in);
    System.out.println("输入用户名");
    String uname = input.next();
    System.out.println("输入密码");
    String upwd = input.next();
    if (uname.equals("zs") && upwd.equals("123")) {
    System.out.println("登录成功");
    } else {
    System.out.println("登录失败");
    }
    returnMain();

    }

    public static void zhuce() {
    Scanner input = new Scanner(System.in);
    System.out.println("用户名");
    String uname = input.next();
    System.out.println("密码");
    String upwd = input.next();
    if (uname.equals(null) || upwd.equals(null)) {
    System.out.println("注册失败");
    } else {
    System.out.println("注册成功");
    }
    returnMain();
    }

    private static void choujiang() {
    Scanner input = new Scanner(System.in);
    System.out.println("请输入四位会员卡号:");
    int x = input.nextInt();
    Random r = new Random();
    int j = r.nextInt(10);
    if (x / 100 * 10 == j) {
    System.out.println("恭喜 你中奖了!");
    } else {
    System.out.println("感谢您的参与");
    }
    returnMain();
    }

    public static void story() {
    Scanner input = new Scanner(System.in);
    System.out.println("请选择你想看的故事:");
    System.out.println("1.从前有座山");
    System.out.println("2.从前有另一座山");
    int a = input.nextInt();
    switch (a) {
    case 1:
    System.out.println("从前有座山,山里有个庙,庙里有个小和尚和老和尚,老和尚给小和尚讲从前有座山……");
    break;
    case 2:
    System.out.println("从前有座山,然后炸了,全剧终");
    break;
    }
    returnMain();
    }

    public static void tuichu() {
    System.out.println("是否退出系统Y/N");
    Scanner input = new Scanner(System.in);
    String a = input.next();
    if (a.equalsIgnoreCase("y")) {
    System.out.println("退出系统成功");
    } else {
    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("谢谢使用");
    }
    }
    }

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

    package a;

    import java.util.*;

    public class jiecheng {
    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) {
    Scanner sc= new Scanner(System.in);
    System.out.println("请输入要求阶乘的数字:");
    int i=sc.nextInt();
    System.out.println("该数字的阶乘为:" + jc(i));
    }
    }

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

    package a;

    import java.util.*;

    public class year {
    public static void year(int n) {
    if (n % 4 == 0 && n % 100 != 0 || n % 400 == 0) {
    System.out.println("该年是闰年");
    } else {
    System.out.println("该年是平年");
    }
    }

    public static void main(String[] args) {
    year a = new year();
    Scanner sc = new Scanner(System.in);
    System.out.println("请输入年份:");
    int i=sc.nextInt();
    year(i);
    }
    }

  • 相关阅读:
    攻防世界新手练习题_MOBILE(移动)
    攻防世界新手练习题_CRYPTO(加密)
    攻防世界新手练习题_REVERSE(逆向)
    攻防世界新手练习题_PWN(漏洞利用)
    攻防世界新手练习题_WEB(渗透)
    攻防世界新手练习题_MISC(杂项)
    数据传输流程图
    leetcode hot 100- 62. 不同路径
    leetcode hot 100
    leetcode hot 100
  • 原文地址:https://www.cnblogs.com/sigure0428/p/12785856.html
Copyright © 2011-2022 走看看