-4

I'm a bloody Java beginner and need some help.

I was wondering what the signature of a public method called "feld" looks like which gets four double numbers and returns a double array.

My exercise says "return a double array". But can i even do that or do i need to return values of my Array? My code won't work at all.

public double [] feld (double q, double w, double e, double r){
            double [] A = {q;w;e;r};
            return A;
}
M. Mc Fly
  • 1
  • 2

3 Answers3

4

Change double [] A = {q;w;e;r}; to double [] A = new double[] {q, w, e, r};

Falla Coulibaly
  • 759
  • 2
  • 11
  • 23
1

try this

public double [] feld (double q, double w, double e, double r){
        return new double[]{q,w,e,r};
}

Your version doesn't work, because the syntax was incorrect.There's a whole question about that here

dumbPotato21
  • 5,669
  • 5
  • 21
  • 34
-1

Do you want to print? İf you want :

public static void main(String [] args){
    double [] a = feld(1,2,3,4);
    for ( double i : a){
        System.out.print(i);
    }
} 

public static double [] feld (double q, double w, double e, double r){
    double [] A = {q,w,e,r};
    return A;}
Yunus Emre
  • 29
  • 1
  • 6