码迷,mamicode.com
首页 > 其他好文 > 详细

第八周zuoye

时间:2020-04-27 13:03:23      阅读:52      评论:0      收藏:0      [点我收藏+]

标签:log   rate   sys   输入   new   幸运   name   auto   switch   

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

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

public class duixiang {
    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:
            zhuce();
            break;
        case 3:
            xingyuncj();
            break;
        case 4:
            xiaogushi();
            break;
        case 5:
            tuichu();
            break;
            
        }
    }

    public 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("zs") && upwd.equals("123")) {
            System.out.println("登录成功");
        } else {
            System.out.println("登录失败");
        }
        returnMain();
    
    }
    public static void zhuce() {
        Scanner input = new Scanner(System.in);
        System.out.println("用户名");
        String uname = input.next();
        System.out.println("密码");
        String upwd = input.next();
        if(uname.equals(null) || upwd.equals(null) ) {
            System.out.println("注册失败");
        }else {
            System.out.println("注册成功");
        }
        returnMain();
    }
    public static void reg() {
        System.out.println("1.失败模式");
        System.out.println("2.正常模式");
        Scanner input = new Scanner(System.in);
        int x=input.nextInt();
        switch(x) {
        case 1:
            zuobi();
            break;
        case 2:
            zhengchang();
            break;
        }
    }
    public static void lose() {
        Scanner input = new Scanner(System.in);
        System.out.println("失败模式:");
        Random r=new Random();
        int sjs=r.nextInt(10);
        System.out.println(sjs);
        System.out.println("请输入四位会员");
        int num=input.nextInt();
        if(num/100%10==sjs) {
            System.out.println("恭喜你,是幸运会员");
        }else {
            System.out.println("祝你下次好运");
        }
        returnMain();
    }
    public static void nom() {
        Scanner input = new Scanner(System.in);
        System.out.println("正常模式");
        Random r=new Random();
        int sjs=r.nextInt(10);
        System.out.println("请输入四位会员数");
        int num=input.nextInt();
        if(num/100%10==sjs) {
            System.out.println("恭喜你,是幸运会员");
        }else {
            System.out.println("祝你下次好运");
        }
        returnMain();
    }
    public static void text() {
        System.out.println("小故事");
         returnmain();
    }
    public static void out() {
        System.out.println("是否退出系统Y/N");
        Scanner input = new Scanner(System.in);
        String a = input.next();
        if(a.equalsIgnoreCase("y")) {
            System.out.println("退出系统成功");
        }else {
            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 duixiang;
import java.util.Scanner;
public class p1 { 
    
    public static int p(int a) {
        int x = 1;
        for (int i = 1; i <= a; i++) {
            x *= i;
        }
        return x;
    }
   
    public static void main(String[] args) {
        System.out.println("请输入数字:");
        Scanner input = new Scanner(System.in);
        int i = input.nextInt();
        System.out.println("阶乘是"+p(i));
    }
}

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

package duixiang;

public class p1 {

    public static void main(String[] args) {
       p1 p = new p1();
            p.method(2000);
        }
        public void method(int year) {
            int a;
            a=year;
            if(a%4==0 && a%100!=0 || a%400==0) {
                System.out.println(a+"是闰年");
            }else {
                System.out.println(a+"不是闰年");
            }

    }

}

 

第八周zuoye

标签:log   rate   sys   输入   new   幸运   name   auto   switch   

原文地址:https://www.cnblogs.com/zhangbowen123/p/12785754.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!