完善menu注册功能,抽奖,看小故事等功能
package demo3;
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 demo3;
public class day01
{
public static void main(String[] args)
{
factorial(4);
}
public static void factorial(int a)
{
int sum=1;
for (int i = 1; i <= a; i++) {
sum=sum*i;
}
System.out.println("阶乘是:"+sum);
}
3.编写-一个方法,判断该年份是平年还是闰年。[必做题]
package demo3;
public class day01
{
public static void main(String[] args)
{
year(2020);
}
public static void year(int a)
{
if (a%4==0&&a%100!=0||a%400==0) {
System.out.println("该年是闰年!");
}
else{
System.out.println("该年不是闰年!");
}
}
}