Here I need to write a method called powArray that takes a double array a and returns a new array that contains the elements of a squared. Generalize it to take a second argument and raise the elements of a to given power.
I tried to write it, but got 0 result, can someone write this and explain how it work, so I could write it in future.
public class Task {
public static void main(String[] args) {
}
public static double powArray (double a[]){
for (int i = 1; i < a.length; i++) {
a[i] = Math.pow(a[i], 2.0);
System.out.print(a[i]);
return powArray(a);
}
return -1;
}
}
Also, after compile got nothing, only clear console w/o any numbers, etc.