• 第八周作业


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

    package a;
    
    	import java.util.Random;
    	import java.util.Scanner;
    
    	public class sss {
    
    	    
    	    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:
    	            zc();
    	            break;
    	        case 3:
    	            cj();
    	            break;
    	        case 4:
    	            storyn();
    	            break;
    	        case 5:
    	            tc();
    	            break;
    	        }
    	    }
    
    	    private 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("lxy") && 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("谢谢使用");
    	        }
    
    	    }
    	    public static void zc(){
    	            Scanner input = new Scanner(System.in);
    	            System.out.println("======注册页面======");
    	            System.out.println("请输入用户名");
    	            String uname = input.next();
    	            System.out.println("输入密码");
    	            String upwd = input.next();
    	            System.out.println("======返回登录页面=====");
    	            login();
    	    }
    	    public static void storyn(){
    	        Scanner input = new Scanner(System.in);
    	        System.out.println("输入故事序号1,2,3,4,5");
    	        int i = input.nextInt();
    	        switch (i) {
    	        case 1:
    	            System.out.println("后羿射日");
    	            break;
    	        case 2:
    	            System.out.println("女娲补天");
    	            break;
    	        case 3:
    	            System.out.println("大禹治水");
    	            break;
    	        case 4:
    	            System.out.println("大闹天宫");
    	            break;
    	        case 5:
    	            System.out.println("小红帽");
    	            break;
    	        }
    	        returnMain();
    	    }
    	    public static void cj(){
    	          Scanner input = new Scanner(System.in);
    	            Random r=new Random();
    	            int x=r.nextInt(10);
    	            System.out.println("随机数是"+x);
    	            System.out.println("请输入四位会员卡号");
    	            int u = input.nextInt();
    	            if(x==u/10%10) {
    	                System.out.println("是幸运会员!");
    	            }else {
    	                System.out.println("不是幸运会员");
    	            }
    	            returnMain();
    	    }
    	     private static void tc() {
    	            System.out.println("是否退出系统?Y/N");
    	            Scanner input = new Scanner(System.in);
    	            if (input.next().equalsIgnoreCase("Y")) {
    	                System.out.println("=====退出系统成功====");
    	            }else{
    	                mainMenu();
    	                
    	            }
    	        }
    
    	}
    

      

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

    package a;
    
    
    public class sss {
            public static int jc(int a){
                int sum=1;
                for (int i = 1; i <=a; i++) {
                    sum*=a;
                    
                    
                }
                return sum;
            }
            public static void main(String[] args) {
                System.out.println(jc(6));
            }
    }
    

      

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

    package a;
    
    
    public class sss {
        public static void main(String[] args) {
            near(2020);
        }
            public static void near(int y){
                 if (y % 4 == 0 && y % 100 != 0 || y % 400 == 0) {
                        System.out.println(y + "年是闰年");
                    } else {
                        System.out.println(y + "年不是闰年");
                    }
            }
    
    }
    

      

  • 相关阅读:
    磁盘及分区管理
    用户和文件权限管理
    分割文件命令split
    去除重复命令uniq
    数据连接命令join
    数据剪切命令cut和数据粘贴命令pastte
    排序命令sort
    koa-router
    koa入门
    require.ensure的用法;异步加载-代码分割;
  • 原文地址:https://www.cnblogs.com/y611lx/p/12772100.html
Copyright © 2020-2023  润新知