• 第八次作业



    package
    dfishf; import java.util.Random; import java.util.Scanner; public class homework { 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 n = input.nextInt(); switch (n) { case 1: login(); break; case 2: zc(); break; case 3: cj(); break; case 4: story(); break; case 5: tc(); break; } } public static void tc() { System.out.println("谢谢使用"); } public static void story() { Scanner input = new Scanner(System.in); System.out.println("请选择想看的故事"); System.out.println("1.jojo1"); System.out.println("2.jojo2"); System.out.println("3.jojo3"); int a = input.nextInt(); switch (a) { case 1: System.out.println("大乔揍dio"); break; case 2: System.out.println("二乔揍阿姨压一压"); break; case 3: System.out.println("三桥继续揍dio"); break; } returnMain(); } private static void choujiang() { Scanner input = new Scanner(System.in); System.out.println("请输入四位会员卡号"); int x = input.nextInt(); Random r = new Random(); int a = r.nextInt(10); if (x / 100 % 10 == a) { System.out.println("恭喜你中奖啦!"); } else { System.out.println("谢谢参与"); } returnMain(); } private static void zhuce() { Scanner input = new Scanner(System.in); System.out.println("请输入用户名"); String name = input.next(); System.out.println("请输入密码"); String mima = input.next(); System.out.println("注册成功"); returnMain(); } private static void login() { 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 returnMain() { System.out.println("是否返回主菜单?Y/N"); Scanner input = new Scanner(System.in); if (input.next().equalsIgnoreCase("Y")) { Mainmenu(); } else { System.out.println("谢谢使用"); } } }

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

    package dfishf;
    
    public class homework {
    
        public static void main(String[] args) {
              jiecheng p=new jiecheng();
                p.method(5);
            }
            public void method(int a) {
                int b=1;
                for(int i=1;i<=a;i++) {
                    b*=i;
                }
                a=b;
                System.out.println(a);
            }
        
    }

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

    package dfishf;
    
    public class homework{
        public static void main(String[] args) {
            prn(2018);
        }
    
        public static void prn(int year) {
            if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) {
                System.out.println(year + "是闰年");
            } else {
                System.out.println(year + "不是闰年");
            }
    
        }
    }

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

  • 相关阅读:
    Java基础16(Java8的其它新特性)
    Java基础15(反射机制)
    Java基础14(网络编程)
    tensorflow.keras
    递归算法
    tensorfolw学习笔记——张量、微分、自定义训练、keras
    python可变长参数、key-only参数之收集和解包参数
    20200909- 集群迁移记录
    20200909--记一次发布流程
    20200909----开发沟通提效记录
  • 原文地址:https://www.cnblogs.com/reddead/p/12796621.html
Copyright © 2020-2023  润新知