zoukankan      html  css  js  c++  java
  • 第九次作业

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

    ackage calsswork;
    import java.util.Scanner;
    public class text1 {
         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:
                         dl();
                         break;
                     case 2:
                         zc();
                         break;
                     case 3:
                         cj();
                         break;
                     case 4:
                         gs();
                         break;
                     case 5:
                         tc();
                         break;
                     }
                 }
                 private static void dl() {
                     Scanner input = new Scanner(System.in);
                     System.out.println("输入用户名");
                     String uname = input.next();
                     System.out.println("输入密码");
                     String upwd = input.next();
                     if (uname.equals("wk") && upwd.equals("123")) {
                         System.out.println("登录成功");
                     } else {
                         System.out.println("登录失败");
                     }
                     returnMain();
                 }
                 private static void zc() {
                     Scanner input = new Scanner(System.in);
                     System.out.println("输入用户名");
                     String uname = input.next();
                     System.out.println("输入密码");
                     String upwd = input.next();
                     System.out.println("注册成功");
                     returnMain();
                 }
                 private static void cj() {
                     Scanner input = new Scanner(System.in);
                     System.out.println("请输入会员卡号");
                     int i = input.nextInt();
                     Random r = new Random();
                     int a = r.nextInt(10);
                     if (a == i / 100 % 10) {
                         System.out.println("恭喜你成为幸运会员");
                     } else {
                         System.out.println("谢谢参与");
                     }
                     returnMain();
                 }
                 private static void gs() {
                     Scanner input = new Scanner(System.in);
                     System.out.println("请选择故事");
                     System.out.println("1.故事");
                     System.out.println("2.故事");
                     int b = input.nextInt();
                     switch (b) {
                     case 1:
                         System.out.println("1");
                         break;
                     case 2:
                         System.out.println("111");
                         break;
                     }
                     returnMain();
                 }
                 private static void tc() {
                     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 calsswork;
    import java.util.Scanner;
    public class text1 {
            public static int jc(int x) {
                int a = 1;
                for (int i = 1; i <= x; i++) {
                    a *= i;
                }
                return a;
            }
            public static void main(String[] args) {
                System.out.println("5的阶乘是:"+jc(5));
            }
        }

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

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

  • 相关阅读:
    批量新增百万条数据 十百万条数据
    sqlserver 组内排序
    EF ++属性会更新实体
    Entity Framework Core: A second operation started on this context before a previous operation completed
    abp Cannot access a disposed object. A common cause of this error is disposing
    abp xunit Can not register IHostingEnvironment. It should be a non-abstract class. If not, it should be registered before.”
    hangfire enqueued but not processing(hangfire 定时任务入队列但不执行)
    EF 更新实体 The instance of entity type 'BabyEvent' cannot be tracked because another instance
    datatable to entiy list 不支持可空类型和枚举类型
    webapi 设置不显示接口到swaggerUI
  • 原文地址:https://www.cnblogs.com/jiming123/p/12795277.html
Copyright © 2011-2022 走看看