请编写程序,实现对数组{25,24,12,76,101,96,28} 的排序,请用JAVA输出
时间: 2023-07-29 15:07:09 浏览: 45
可以使用Java中的Arrays.sort()方法对数组进行排序,如下所示:
```java
import java.util.Arrays;
public class SortArray {
public static void main(String[] args) {
int[] arr = {25,24,12,76,101,96,28};
Arrays.sort(arr);
for (int i : arr) {
System.out.print(i + " ");
}
}
}
```
输出结果为:
```
12 24 25 28 76 96 101
```
相关问题
用java请使用冒泡排序算法编写程序,实现对数组{25,24,12,76,101,96,28}的排序。
好的,以下是Java实现冒泡排序算法的程序:
```java
public class BubbleSort {
public static void main(String[] args) {
int[] arr = {25, 24, 12, 76, 101, 96, 28};
bubbleSort(arr);
System.out.println(Arrays.toString(arr));
}
public static void bubbleSort(int[] arr) {
for (int i = 0; i < arr.length - 1; i++) {
for (int j = 0; j < arr.length - 1 - i; j++) {
if (arr[j] > arr[j + 1]) {
int temp = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = temp;
}
}
}
}
}
```
输出结果为:`[12, 24, 25, 28, 76, 96, 101]`。
请编写程序,实现对数组{25,24,12,76,101,96,28} 的排序. 提示:使用冒泡排序算法.用java语言实现
以下是使用Java语言实现冒泡排序算法的程序,对数组{25,24,12,76,101,96,28}进行排序:
```java
public class BubbleSort {
public static void main(String[] args) {
int[] arr = {25, 24, 12, 76, 101, 96, 28};
bubbleSort(arr);
System.out.println("排序后的数组:");
for (int i = 0; i < arr.length; i++) {
System.out.print(arr[i] + " ");
}
}
public static void bubbleSort(int[] arr) {
int temp;
for (int i = 0; i < arr.length - 1; i++) {
for (int j = 0; j < arr.length - 1 - i; j++) {
if (arr[j] > arr[j + 1]) {
temp = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = temp;
}
}
}
}
}
```
输出结果为:
```
排序后的数组:
12 24 25 28 76 96 101
```
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)