# java第十周作业

1.编写一个方法，实现冒泡排序（由小到大），并调用该方法

package word;

import java.util.Scanner;

public class test1 {
public static void main(String[] args){
Scanner input=new Scanner(System.in);
System.out.println("请输入五个数");
int []a=new int [5];
for(int i=0;i<a.length;i++){
a[i]= input.nextInt();
}
px(a);
for (int i = 0; i <a.length ; i++) {
System.out.print(a[i]+" ");
}
}

private static void px(int[] a) {
// TODO Auto-generated method stub
for (int i = 0; i < a.length; i++) {
for(int j=0;j<a.length;j++){
if (a[i]<a[j]) {
int temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}

}
}

2.编写一个方法，求整数n的阶乘，例如5的阶乘是1*2*3*4*5。 [必做题]

package word;

public class test1 {
public static int jc(int n) {
int sum = 1;
for (int i = 1; i <= n; i++) {
sum *= i;
}
System.out.println("阶乘为:");
return sum;
}

public static void main(String[] args) {
System.out.println(jc(5));
}
}

3.编写一个方法，判断该年份是平年还是闰年。

package word;

import java.util.Scanner;

public class test1 {
public static void panduan() {
Scanner input = new Scanner(System.in);
System.out.println("请输入年份:");
int year = input.nextInt();
if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) {
System.out.println("闰年");
} else {
System.out.println("平年");
}
}

public static void main(String[] args) {
panduan();
}
}

 package word;

import java.util.Scanner;

public class test1 {
public static void mainMenu() {
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:
register();
break;
case 3:
xycj();
}
}

public static void returnMain() {
Scanner input = new Scanner(System.in);
System.out.println("是否返回主菜单？Y/N");
if (input.next().equalsIgnoreCase("Y"))
else
System.out.println("谢谢使用");
}

public static void login() {
Scanner input = new Scanner(System.in);
System.out.println("输入用户名");
String uname = input.next();
System.out.println("输入密码");
String pwd = input.next();
System.out.println("成功");
else
System.out.println("失败");
returnMain();
}

public static void register() {
Scanner input = new Scanner(System.in);
System.out.println("输入用户名");
String uname = input.next();
System.out.println("输入密码");
String pwd = input.next();
System.out.println("注册成功");
returnMain();
}

public static void xycj() {
Scanner input = new Scanner(System.in);
System.out.println("请输入四位数卡号:");
int kahao = input.nextInt();
int random = (int) (Math.random() * 10);
if (random == kahao / 100 % 10) {
System.out.println("恭喜你是幸运会员!");
} else {
System.out.println("幸运数是:" + random);
System.out.println("很遗憾你不是幸运会员!");
}
returnMain();
}

public static void main(String[] args) {
}