冒泡排序

package exercise;

import java.util.Arrays;
import java.util.Scanner;

import javax.swing.plaf.synth.SynthStyle;

public class Exe2_Maopao {

    public static void main(String[] args) {
        int temp;    //交换数据用
        int[] Price = new int[4];    //定义数组
        Scanner input = new Scanner(System.in);
        
        //输入数据
        for (int i = 0 ;i < 4; i++){
            System.out.println("第"+(i+1)+"店价格:");
            Price[i] = input.nextInt();
        }
        //执行轮数
        int k;
        for (int j = 0;j < 4; j++){
            //执行一轮结果
            for(k = 0; k < 4-j-1; k++){
                if(Price[k] < Price[k+1] ){
                    temp = Price[k];
                    Price [k] = Price [k+1];
                    Price [k+1] = temp;
                }
            }
        //输出每一轮的最小数
        System.out.print(Price[k]+"\t");
        }
        System.out.println("\n最低价格是:"+Price[3]);
        input.close();
    }
}

 

posted @ 2016-07-29 15:07  me丶不是好人  阅读(94)  评论(0编辑  收藏  举报