Spot up to 10 errors in Java and FIX them public static void

Spot up to 10 errors in Java and FIX them!

public static void main (String [] args) {int [] spaceshipDiameters = new {20, 85, 34, 62, 45}; System out.println(\"The average spaceship\'s area is\" + getAverageSpaceshipArea(spaceshipDiameters []));} public double getAverageSpaceshipArea (int [] s) {for (int i = 0: i

Solution

Hi,

I have fixed the issues and it is working fine now. Highlighted the code changes below.

Test.java


public class Test {
   public static void main(String[] args) {
       int[] spaceshipDiameters = new int[]{20,85,34,62,45};
       System.out.println(\"The average spaceship area is \"+getAverageSpacesshipArea(spaceshipDiameters));
   }
   public static double getAverageSpacesshipArea(int[] s){
       double total = 0;
      
for(int i=0; i<s.length; i++){
           double currentArea = Math.PI * s[i] * s[i];
           total+=currentArea;
       }
       return total;
   }
}

Output:

The average spaceship area is 46024.332375090475

Spot up to 10 errors in Java and FIX them! public static void main (String [] args) {int [] spaceshipDiameters = new {20, 85, 34, 62, 45}; System out.println(\

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site