8-31号的数组练习
* 实验任务
实验任务
将数组中的一组数据,从小到大依次输出
实验要求
数组必须是数字类型
随机定义一组数组
package testof8_31;
import java.util.Arrays;
/**
* @author HP-Developer
* 8-31号的数组练习
* 实验任务
实验任务
将数组中的一组数据,从小到大依次输出
实验要求
数组必须是数字类型
随机定义一组数组
*/
public class Test3{
public static void main(String[] args){
int [] num={2,3,456,78,32,6,8,4,87,345};
int temp;
for(int i=0;i<num.length;i++){
for(int j=0;j<num.length-1;j++){
if(num[j]>=num[j+1]){
temp=num[j];
num[j]=num[j+1];
num[j+1]=temp;
}
}
}
for(int i:num){
System.out.print(i+"\t");
}
System.out.print("\n");
int [] num1={2,3,456,78,32,6,8,4,87,345};
Arrays.sort(num1);
for(int i:num1){
System.out.print(i+"\t");
}
}
}
/*输出结果是:
2 3 4 6 8 32 78 87 345 456
2 3 4 6 8 32 78 87 345 456*/