Java程序第九次作业

package com.homework07;

public class MyClass {
    public int[] sort(int[] array) {
        int t;
        for (int n = 0; n < array.length; n++) {
            for (int m = n; m < array.length; m++) {
                if (array[m] < array[n]) {
                    t = array[m];
                    array[m] = array[n];
                    array[n] = t;
                }
            }
        }
        return array;
    }

package com.homework07;

public class Assignment01 {
    public static void main(String[] args) {
        int[] array = { 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 };
        MyClass myClass = new MyClass();
        int[] newArray = new int[array.length];
        newArray = myClass.sort(array);
        for (int value : newArray) {
            System.out.print(value + " ");
        }
        System.out.println();
    }
}


package com.homework07;

public class MyClass {
    int factorial(int target) {
        int result = 1;
        for (int n = target; n > 1; n--) {
            result *= n;
//            System.out.print(n + " ");
        }
        return result;
    }
}

package com.homework07;

public class Assignment02 {
    public static void main(String[] args) {
        MyClass myClass = new MyClass();

        System.out.println(myClass.factorial(10));
    }
}



package com.homework07;

public class MyClass {
    boolean year(int target) {
        if (target % 4 == 0 && target % 100 != 0 || target % 400 == 0) {
            return true;
        }
        else {
            return false;
        }
    }
}

package com.homework07;
import java.util.Scanner;

public class Assignment03 {
    public static void main(String[] args) {

        MyClass myClass = new MyClass();
        Scanner scanner = new Scanner(System.in);
        if (myClass.year(scanner.nextInt())) {
            System.out.println("是");
        }
        else {
            System.out.println("否");
        }
    }
}

posted @ 2021-05-10 20:01  SuoJing  阅读(57)  评论(0编辑  收藏  举报