Java程序设计
程序设计题目
如题
Java程序设计
程序设计题目
如题
冒泡
public static void main(String[] args) {
int array[] = { 2, 13, 45, 1, 98, 12, 44 };
int i = 0, j = 0, temp = 0;
for (i = 0; i < array.length; i++) {
for (j = 0; j < array.length - i; j++) {
if (array[j] < array[j + 1]) {
temp = array[j];
array[j] = array[j + 1];
array[j + 1] = temp;
}
}
}
for (i = 0; i < array.length; i++) {
System.out.println(array[i]);
}
public class Sort { public static void main(String[] str){
int[] num = new int[3]; int[] count = {2,13,45,1,98,12,44}; int temp=0; for(int i=0;i<count.length; i++){ for(int j=0; j<count.length-1-i; j++){ if(count[j]>count[j+1]){ temp=count[j]; count[j] = count[j+1]; count[j+1] = temp; } } } for(int i=0; i<count.length; i++){ System.out.println(count[i]); } } }