67,512
社区成员
发帖
与我相关
我的任务
分享
public class test2 {
public static void main(String[] args) {
// TODO Auto-generated method stub
int arr[] = { 23, 56, 43, 22, 1, 67, 98, 70 };
System.out.print("排序前的数组元素为:");
for (int a : arr) {
System.out.print(a + " ");
}
System.out.println();
for (int n = 0; n < arr.length - 1; n++) {
for (int j = 0; j < arr.length - n - 1; j++) {
int temp = 0;
if (arr[j] > arr[j + 1]) {
temp = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = temp;
}
}
}
System.out.print("排序后的数组元素为:");
for (int s : arr) {
System.out.print(s + " ");
}
}
}
还有n应该从1开始循环 if后面应该用大括号框住后面的三句话
if后面应该用大括号框住后面的三句话