Glame

JAVA第十次作业

import java.util.Scanner;

public class MyMethod {
    public static void PX() {
        System.out.println("请输入4个数字");
        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; j++) {
                if (a[j] > a[j + 1]) {
                    int temp = a[j];
                    a[j] = a[j + 1];
                    a[j + 1] = temp;
                }
            }
        }
        for (int i : a) {
            System.out.println(i);
        }

    }

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

    }
}

import java.util.Scanner;

public class MyMethod {
    public static void JC() {
        Scanner input = new Scanner(System.in);
        System.out.println("请输入()的阶乘");
        int n = input.nextInt();
        int sum = 1;
        for (int i = 1; i <= n; i++) {
            sum = sum * i;
        }
        System.out.println(sum);
    }

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

    }
}

import java.util.Scanner;

public class MyMethod {
    public static void year() {
        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(year + "是闰年");
        else
            System.out.println(year + "是平年");
    }

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

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


public class Menu {
    
    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:
            login();
            break;
        case 2:
            reg();
            break;
        case 3:
            lucky();
        
        }
        
        
    }
    
    private static void lucky() {
        // 输入四位会员卡号,如果百位数等于随机数,幸运会员。否则不是。同时也要询问是否返回主菜单
        Random r=new Random();
        int a=r.nextInt(10);
        Scanner input=new Scanner(System.in);
        int num=input.nextInt();
        int luckynum=num/100%10;
        System.out.println("今天的幸运数字是"+a);
        if(luckynum==a){
            System.out.println("恭喜你 成为幸运会员");    
        }
        else
            System.out.println("谢谢惠顾");
        returnMain();
    }

posted on 2021-05-10 22:47  Glame  阅读(58)  评论(0编辑  收藏  举报

导航