# 第九次Java作业

1.编写一个方法，

public class test {
public static void mppx(){
Scanner input = new Scanner(System.in);
int a[] = new int[4];
for(int i=0;i<a.length;i++){
a[i]=input.nextInt();
}
for(int i=0;i<a.length-1;i++){
for (int j = 0; j < a.length-1-i; j++) {
if(a[j]>a[j+1]){
int max=a[j];
a[j]=a[j+1];
a[j+1]=max;
}
}
}
for (int i = 0; i < a.length; i++) {
System.out.println(a[i]);
}
}
public static void main(String[] args) {
mppx();
}

}

2编写一个方法，求n的阶乘

public class test {
public static int j(int n) {
int sum = 1;
for (int i = 1; i <= n; i++) {
sum = sum * i;
}
return sum;
}

public static void main(String[] args) {
System.out.println("阶乘为" + j(6));
}3.编写一个方法，判断该年份是平年还是闰年。[必做题]

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

package homework9;

public class Test3 {

public static int pr(int n){
if(n%4==0&&n%100!=0||n%400==0)
System.out.println("是闰年");
else
System.out.println("是平年");
return n;
}

public static void main(String[] args){
System.out.println(pr(2020));

}

}

package task;

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

public class T1 {

public static void main(String[] args) {
}
Scanner input = new Scanner(System.in);
System.out.println("欢迎使用本系统");
System.out.println("1.登录");
System.out.println("2.注册");
System.out.println("3.幸运抽奖.");
System.out.println("4.退出系统");
System.out.println("请选择");
int i = input.nextInt();
switch (i) {
case 1:
break;
case 2:
zhuce();
break;
case 3:
xingyuncj();
break;
case 4:
tuichu();
break;

}
}

// 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 xingyuncj() {
Scanner input = new Scanner(System.in);
System.out.println("幸运抽奖");
System.out.println("输入会员号");
int a=input.nextInt();
Random i=new Random();
int b=i.nextInt(10);
if(a==b) {
System.out.println("恭喜中奖");
}
else
{
System.out.println("未中奖");
}
returnMain();
}

public static void tuichu() {
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")) {
}