Java 一维数组
程序员文章站
2022-03-04 20:44:58
...
/**
* Java 一维数组
* dataType[] arrayRefVar = new type[typeLength1];
*/
public class learn_13_1 {
public static void main(String[] args) {
int size = 10;
double[] arrayDouble = new double[size];
for (int i = 0; i < size; i++){
arrayDouble[i] = Math.random();
}
for (int i = 0; i < size; i++){
System.out.println(arrayDouble[i]);
}
System.out.println("=================");
for (double array: arrayDouble
) {
System.out.println(array);
}
System.out.println("=================");
System.out.println(printArray(arrayDouble));
System.out.println("=================");
for (double array: reverse(arrayDouble)
) {
System.out.println(array);
}
}
public static double printArray(double[] arrays){
double d = 0;
for (double array:arrays
) {
d = d+array;
}
return d;
}
public static double[] reverse(double[] lists) {
int length = lists.length;
for (int i = 0; i < length; i++){
lists[i] = lists[i] * 100;
}
return lists;
}
}