class arrayList{
public static void arr(){
double arr[] = new double[4];
Scanner sc = new Scanner(System.in);
System.out.println("Please enter a number !!");
for (int i = 0; i < arr.length; i++) {
arr[i] = sc.nextDouble();
}
for (int i = 0; i < arr.length; i++) {
System.out.print(arr[i] + " ");
}
double max = arr[0];
double min = arr[0];
double minn=1;
double maxn=1;
for (int i = 0; i < arr.length; i++) {
if(arr[i] > max)
max = arr[i];
if(arr[i] <min)
min = arr[i];
}
System.out.println("\n"+max + min);
for (int i = 0; i < arr.length; i++) {
if(max == arr[i]){
minn = i+ 1;
}
if (min == arr[i]) {
maxn = i+1;
}
}
System.out.println("标号是" + minn + maxn);
//排序
for (int i = 0; i < arr.length; i++) {
for (int j = 0; j < arr.length; j++) {
if(arr[i] > arr[j]){
double temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
}
}
for (int i = 0; i < arr.length; i++) {
System.out.println(arr[i]);
}
} |
|