2个回答
展开全部
int[] arr = { 1, 3, 2, 6, 4, 5 };
int n = arr.length;
int temp;
for (int i = 1; i <= n - 1; i++) {
for (int j = n - 1; j >= 1; j--) {
if (arr[j] > arr[j - 1]) {
temp = arr[j];
arr[j] = arr[j - 1];
arr[j - 1] = temp;
}
}
}
System.out.println("降序排序后:");
for (int i = 0; i < n; i++) {
System.out.print(" " + arr[i]);
}
for (int i = 1; i <= n - 1; i++) {
for (int j = n - 1; j >= 1; j--) {
if (arr[j] < arr[j - 1]) {
temp = arr[j];
arr[j] = arr[j - 1];
arr[j - 1] = temp;
}
}
}
System.out.println();
System.out.println("升序排序后:");
for (int i = 0; i < n; i++) {
System.out.print(" " + arr[i]);
}
int n = arr.length;
int temp;
for (int i = 1; i <= n - 1; i++) {
for (int j = n - 1; j >= 1; j--) {
if (arr[j] > arr[j - 1]) {
temp = arr[j];
arr[j] = arr[j - 1];
arr[j - 1] = temp;
}
}
}
System.out.println("降序排序后:");
for (int i = 0; i < n; i++) {
System.out.print(" " + arr[i]);
}
for (int i = 1; i <= n - 1; i++) {
for (int j = n - 1; j >= 1; j--) {
if (arr[j] < arr[j - 1]) {
temp = arr[j];
arr[j] = arr[j - 1];
arr[j - 1] = temp;
}
}
}
System.out.println();
System.out.println("升序排序后:");
for (int i = 0; i < n; i++) {
System.out.print(" " + arr[i]);
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询