package com.bank.cn;
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
float[] x = new float[5];
float sum=0;
for(int i=0;ix[i] = scanner.nextInt();
sum+=x[i];
}
System.out.println("平均数是:"+(float)(sum)/5);
System.out.println("排序前:");
System.out.println(x.length);
for(float k:x) {
System.out.print(k+"\t");
}
float[] x1 = new float[5];
x1 = sort(x);
System.out.println("\n排序后:");
for(float i:x1) {
System.out.print(i+"\t");
}
}
//排序
private static float[] sort(float[] x) {
for(int i=0;ifor(int j=i;j if(x[i] float temp = x[i];
x[i]=x[j];
x[j]=temp;
}
}
}
return x;
}
}
结果:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import java.util.Scanner;
public class Array {
public static void main(String[] args) {
float[] f=new float[5];
double [] d=new double[5];
System.out.println("给float数组赋值");
Scanner sc=new Scanner(System.in);
f[0]= new Float(sc.nextFloat());
f[1]= new Float(sc.nextFloat());
f[2]= new Float(sc.nextFloat());
f[3]= new Float(sc.nextFloat());
f[4]= new Float(sc.nextFloat());
System.out.println("遍历float数组");
for(float ff:f){
System.out.print(ff+"+++++");
}
System.out.println();
System.out.println("--------------------------------------------------------------------");
System.out.println("给double数组赋值");
Scanner sc1=new Scanner(System.in);
d[0]=new Double(sc1.nextDouble());
d[1]=new Double(sc1.nextDouble());
d[2]=new Double(sc1.nextDouble());
d[3]=new Double(sc1.nextDouble());
d[4]=new Double(sc1.nextDouble());
System.out.println("遍历doub