1.编写一个方法,实现冒泡排序(由小到大),并调用该方法

import java.util.Scanner;


public class hhh {
        
    
    
        
        public static void px() {
            Scanner input = new Scanner(System.in);
            System.out.println("输入5个数:");
            int a[] = new int[5];
            int b;
            for (int i = 0; i < a.length; i++) {
                a[i] = input.nextInt();
            }
            for (int i = 0; i < a.length - 1; i++) {
                for (int j = i+1; j < a.length; j++) {
                    if (a[i] > a[j]) {
                        b = a[i];
                        a[i] = a[j];
                        a[j] = b;
                    }
                }
            }
            for (int i = 0; i < a.length; i++) {
                System.out.print(a[i]);
                System.out.print("  ");
            }
            System.out.println();
        }
        public static void main(String[] args) {
            px();
        }
    }

    
   

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

import java.util.Scanner;
public class hhh{
    
    public static int jc(int a){
        int sum=1;
        for(int i=1;i<=a;i++){
            sum*=i;
        }
        return sum;
    }
    public static void main(String[] args){
        System.out.println(jc(5));
    }
}

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

import java.util.Scanner;
public class hhh{
    
    public static void jj() {
        Scanner input=new Scanner(System.in);
        int a=input.nextInt();
         if (a % 400 == 0 & a % 100 != 0 | a % 4 == 0)
             System.out.println("闰年");
         else
             System.out.println("平年");
     }
    public static void main(String[] args) {
        pr();
    }
}

4.课堂没完成的menu菜单,实现幸运抽奖功能

import java.util.Scanner;


public class hhh {
        
    
    
        
        public static void px() {
            Scanner input = new Scanner(System.in);
            System.out.println("输入5个数:");
            int a[] = new int[5];
            int b;
            for (int i = 0; i < a.length; i++) {
                a[i] = input.nextInt();
            }
            for (int i = 0; i < a.length - 1; i++) {
                for (int j = i+1; j < a.length; j++) {
                    if (a[i] > a[j]) {
                        b = a[i];
                        a[i] = a[j];
                        a[j] = b;
                    }
                }
            }
            for (int i = 0; i < a.length; i++) {
                System.out.print(a[i]);
                System.out.print("  ");
            }
            System.out.println();
        }
        public static void main(String[] args) {
            px();
        }
    }

 posted on 2021-05-12 14:22  莉莉娅king  阅读(43)  评论(0编辑  收藏  举报