• 4.28


    1.完善menu注册功能,抽奖,看小故事等功能
    package learn;
    
    import java.util.Random;
    import java.util.Scanner;
    
    public class day25 {
    
        public static void main(String[] args) {
            mainMenu();
        }
        
             public static void mainMenu() {
                 Scanner input = new Scanner(System.in);
                 System.out.println("****************Menu**************");
             1    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 learn;
    import java.util.*;
    public class day25 {
     
        public static void main(String[] args) {
            // TODO Auto-generated method stub
            jiec();
        }
        public static void jiec(){
            Scanner input =new Scanner(System.in);
            int sum=1;
            System.out.println("请输入一个整数");
            int a=input.nextInt();
            for (int i = 1; i <= a; i++) {
                sum*=i;
                 
            }
             System.out.println("阶乘为"+sum);
        }
    }
    3.编写一个方法,判断该年份是平年还是闰年。[必做题]
    package learn;
    import java.util.*;
    public class day25 {
     
        public static void main(String[] args) {
            // TODO Auto-generated method stub
            nian();
        }
        public static void nian(){
            Scanner input=new Scanner (System.in);
            System.out.println("请输入 年份");
            int n=input.nextInt();
            if(n%400==0){
                System.out.println(n+"年是闰年");
            }else{
                System.out.println(n+"年是平年");
            }
        }
     
    }
  • 相关阅读:
    ESP8266简单几步建立服务器
    SVM推导
    标准的最大margin问题
    switch用法
    vecor预分配内存溢出2
    vector预分配空间溢出
    [面试编程题]算法基础-字符移位
    [面试编程题1]构造回文
    一天学完UFLDL
    神经网络中的XOR问题
  • 原文地址:https://www.cnblogs.com/xiaomoa/p/12793343.html
Copyright © 2020-2023  润新知