JAVA.12
2021-02-08 18:15
标签:抽奖 new int() else ++ bre uname out rand JAVA.12 标签:抽奖 new int() else ++ bre uname out rand 原文地址:https://www.cnblogs.com/Libreation/p/12770308.htmlimport java.util.Random;
import java.util.Scanner;
public class Y1 {
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.龟兔赛跑");
System.out.println("2.农夫与蛇");
System.out.println("3.狼来了");
int a = input.nextInt();
switch (a) {
case 1:
System.out.println("兔乌赛跑,龟到终点。");
break;
case 2:
System.out.println("农夫救蛇,不知回报。");
break;
case 3:
System.out.println("狼来了。");
break;
}
returnMain();
}
private static void cj() {
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 zc() {
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("谢谢使用");
}
}
}
2.编写一个方法,求整数n的阶乘,例如5的阶乘是1*2*3*4*5。
public classY1 {
public static int jc(int a) {
int x = 1;
for (int i = 1; i
3.编写一个方法,判断该年份是平年还是闰年。
public class Y1 {
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 + "年不是闰年");
}
}