1:完善menu注册功能,抽奖,看小故事等功能
package test;
import java.util.Scanner;
public class person {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
String A = "y";
do {
System.out.println("*************管 理 系 统************");
System.out.println(" 1.注册");
System.out.println(" 2.登录");
System.out.println(" 3.抽奖");
System.out.println("*****************************************");
System.out.println("
请选择菜单:");
int choice = input.nextInt();
int random = (int) (Math.random() * 4000);
switch (choice) {
case 1:
System.out.println("购物管理系统>注册");
System.out.println("请填写个人注册信息:");
System.out.print("请输入用户名:");
String name = input.next();
System.out.print("请输入密码:");
String pwd = input.next();
System.out.println("
注册成功!请您记住您的会员卡号:");
System.out.println("用户名 密码 会员卡号");
System.out.println(name + " " + pwd + " " + random);
break;
}
System.out.println("是否继续(y / n ):");
A = input.next();
} while (A.equals("y"));
System.out.println("谢谢使用");
}
}
编写一个方法,求整数n的阶乘,例如5的阶乘是1*2*3*4*5。 [必做题]
package test;
import java.util.Scanner;
public class personcrate {
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 <= k; i++) {
sum=sum*i;
}
System.out.println(k+"的阶乘为:"+sum);
}
}
3.编写一个方法,判断该年份是平年还是闰年。[必做题]
package test;
import java.util.Scanner;
public class personcrate {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.print("请输入要判定的年份:");
int year = in.nextInt();
if(year%4==0 || year%400==0) {
System.out.println(year+" 是闰年");
} else {
System.out.println(year+" 不是闰年");
}
}
}