小题目一只,大家都来参与
用冒泡法给此数组排序,没难度的童鞋就不要贴了,俺们之中刚接触java的来研究。private int[]i={12,13,23,45,43,33,24,46,34};
public class test { private int[] s = {14,13,23,45,43,33,24,46,34}; public void sort() { int temp; for (int i = 0; i < 8; ++i) for (int j = 0; j < 8 - i; ++j) if (s[j] > s[j+1]) {temp = s[j]; s[j] = s[j+1]; s[j+1] = temp;} } public void Display() { for (int i = 0; i < 9; System.out.println(s[i++])); } public static void main(String [] args) { test a = new test(); a.sort(); a.Display(); } }