import java.util.*;
public class ZiFuChuanZhuanHuanShuZu {
public static void main(String[] args) {
System.out.println("请输入一个数组(中间用空格隔开):");
Scanner sc = new Scanner(System.in);
//获取一个输入的字符串
String s = sc.nextLine();
//将字符串按空格进行裁剪,成为字符组
String[] sa = s.split(" ");
System.out.println("您输入的数组是:");
//遍历输入的字符组
for (String i:sa)
{
System.out.print(i +" ");
}
System.out.println();
//定义一个int型的数组,用来以后判断
int[] n = new int[sa.length];
for (int i = 0;i < n.length ;i++ )
{
//利用for循环,将字符组遍历转换为int型数组
n[i] = Integer.parseInt(sa[i]);
}
//对数组元素按大小排序方法
for (int j = 0;j<sa.length ;j++ )
{
for (int k = 0;k < sa.length ;k++ )
{
if (n[j] < n[k])
{
//3行换位代码
int temp = n[k];
n[k] = n[j];
n[j] = temp;
}
}
}
System.out.println("从小到大排序为:");
for (int x = 0;x < n.length ;x++ )
{
System.out.print(n[x] + " ");
}
System.out.println("\n" + "最小值为:" +n[0] + "\n" +
"最大值为:" + n[n.length - 1] );
}
}