Java_200429

2021-02-03 19:16

阅读:408

标签:switch   数字   long   eth   als   gis   个数   gen   哈哈   

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

package ffeng;

import java.util.Random;
import java.util.Scanner;

public class Menu {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
            mainMenu();
            
    }

    private static void mainMenu() {
        // TODO Auto-generated method stub
        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("6:选择");
        int i = input.nextInt();
        switch (i) {
        case 1:
            logIn();
            break;
        case 2:
            register();
            break;
        case 3:
            luck();
            break;
        case 4:
            story();
            break;
        case 5:
            back();
            break;
        default:
            break;
        }
    }

    private static void back() {
        // TODO Auto-generated method stub
        System.out.println("再见了,我终于弄完了");
    }

    private static void story() {
        // TODO Auto-generated method stub
        Scanner input = new Scanner(System.in);
        System.out.println("1:狼");
        System.out.println("2:蛇");
        System.out.println("3:小猪");
        System.out.println("选择");
         int a = input.nextInt();
         switch (a) {
        case 1:
            wolf();
            break;
        case 2:
            snake();
            break;
        default:
            pig();
            break;
        }
         mainMenu();
    }

    

    private static void pig() {
        // TODO Auto-generated method stub
        System.out.println("从前,有头猪,我不知道了");
        backMain();
    }

    private static void snake() {
        // TODO Auto-generated method stub
        System.out.println("蛇有毒,哈哈啊哈");
        backMain();
    }

    private static void wolf() {
        // TODO Auto-generated method stub
        System.out.println("我是一头狼,哈哈啊哈");
        backMain();
    }

    private static void luck() {
        // TODO Auto-generated method stub
        Scanner input = new Scanner(System.in);
        System.out.println("输入4个数字");
         int a = input.nextInt();
         Random r = new Random();
         int i = r.nextInt(9);
         int k = r.nextInt(9);
         int q,s;
         q=a/1000;
         s=a%100/10;
         if(q==i&&s==k) {
            System.out.println("幸运顾客,奖1万块");
        }
         else{
             System.out.println("谢谢惠顾!");
         }
         mainMenu();
    }

    private static void register() {
        // TODO Auto-generated method stub
        Scanner input = new Scanner(System.in);
        System.out.println("输入姓名");
        String uname = input.nextInt();
        Scanner input = new Scanner(System.in);
        System.out.println("输入性别");
        char sex= input.nextInt();
        System.out.println("输入年龄");
        int  age= input.nextInt();
        System.out.println("输入密码");
        long a = input.nextInt();
        System.out.println("注册成功");
        mainMenu();
    }

    private static void logIn() {
        // TODO Auto-generated method stub
        Scanner input = new Scanner(System.in);
        System.out.println("输入姓名");
        String uname = input.nextInt();
        System.out.println("输入密码");
        String a = input.nextInt();
        if (uname.equals("xxl")&&a.equals(123456)) {
            System.out.println("登录成功");
        }
        else{
            System.out.println("登陆失败");
        }
        backMain();
    }

    private static void backMain() {
        // TODO Auto-generated method stub
        Scanner input = new Scanner(System.in);
        System.out.println("是否返回主菜单");
        int i=input.nextInt();
        if (input.next().equalsIgnoreCase("Y")) {
            mainMenu();
        }
        else{
            System.out.println("谢谢使用");
        }
    }

}

 

 

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

package ffeng;

import java.util.Scanner;

public class f01 {

    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 ) {
            sum=sum*i;
        }
        System.out.println(k+"的阶乘为:"+sum);
    }
}

 

Java_200429

标签:switch   数字   long   eth   als   gis   个数   gen   哈哈   

原文地址:https://www.cnblogs.com/Fzippoby/p/12800396.html


评论


亲,登录后才可以留言!