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

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


    package zuoye; 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("****************Menu**************"); 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.println(" 请选择菜单:"); int i = input.nextInt(); switch (i) { case 1: login();break; case 2: zhuce();break; case 3: choujiang();break; case 4: xiaogushi();break; case 5: System.out.println("退出系统"); default: System.out.println("输入错误!"); returnMain(); break; } } private static void zhuce() { Scanner input=new Scanner(System.in); System.out.println("请输入用户名:"); String name=input.next(); System.out.println("请输入密码:"); String password=input.next(); if(name.equals("李四")&&password.equals("123456")) { System.out.println("注册成功"); }else { System.out.println("注册失败"); } returnMain(); } private static void login() { Scanner input=new Scanner(System.in); System.out.println("请输入用户名:"); String name=input.next(); System.out.println("请输入密码:"); String pwd=input.next(); if(name.equals("李四")&&pwd.equals("123456")) { System.out.println("登录成功"); }else { System.out.println("登录失败"); } returnMain(); } private static void choujiang() { Scanner input=new Scanner(System.in); Random r=new Random(); System.out.println("请输入一个四位数:"); int x=input.nextInt(); int y=r.nextInt(10); if(x/100%10==y) { System.out.println("幸运会员"); }else { System.out.println("很遗憾您不是幸运会员"); } returnMain(); } private static void xiaogushi() { Scanner input=new Scanner(System.in); System.out.println("请选择您要看的小故事:1.格林童话"); int z=input.nextInt(); switch(z) { case 1: System.out.println("格林童话"); default: 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("谢谢使用"); } } }
    2.编写一个方法,求整数n的阶乘,例如5的阶乘是1*2*3*4*5

    package zuoye; import java.util.Scanner; public class zuoyea { 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); } }
    3.编写一个方法,判断该年份是平年还是闰年。


    package zuoye; import java.util.Scanner; public class zuoyea { public static
    void main(String[] args) { Scanner input = new Scanner(System.in); System.out.println("请输入一个年份:"); long year = input.nextLong(); if((year%4==0 && year%100!=0) || year%400==0 ){ System.out.println(year+"年是闰年!"); }else{ System.out.println(year+"年不是闰年!"); } } }
  • 相关阅读:
    css 实现换肤几种方式
    vue 使用中的小技巧 (一)
    GitLab集成Jenkins、Harborn构建pipeline流水线任务
    GitLab数据迁移
    Jenkins更换国内插件源以及Jenkins更新(Jenkins部署在Docker中)
    docker-compose安装JenKins
    docker-compose安装Nexus
    docker-compose安装GitLab
    安装Harbor并修改默认使用的80端口
    在CentOS7.5中基于docker-compose安装mysql5.7
  • 原文地址:https://www.cnblogs.com/z917/p/12792241.html
Copyright © 2011-2022 走看看