Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.

# Thread: Coding Help with Arrays

1. ## Coding Help with Arrays

Code:
```public class ArrayMethods
{
private double[] a;

public static double sumOfArrays(double[] a)
{
double max = a[0];

for(int i =1; i<a.length; i++)
{
if(a[i] > max)
max = a[i];
}

double min = a[1];
for(int i =1; i<a.length; i++)
{
if(a[i] < min)
min = a[i];
}

double difference = max - min;
return difference;
}

public static void main(String[] args)
{
double [] b = {43.9,12.3,99.6,48.2,2.1,65.5};
double diff = differenceOfArrays(b);
System.out.println(diff);
}
}```
When I run the code, at the line where I run the method I wrote, double diff = differenceOfArrays(b);, it says it cannot find the symbol. Before I wrote it, I didn't have the method as static and when I didn't have static there it said that it couldn't be dereferenced. So I made it static. Could anyone help with this? It would be greatly appreciated.

2. You have no method called differenceOfArrays. All you have here is sumOfArrays, although given what it does I'd suspect it should have its signature changed to differenceOfArrays.
An easier solution btw would be to first sort the array from Arrays.sort, then pull both the first and last elements in the array, and calculate the difference. Otherwise, you can perform both the max and the min within the same loop by evaluating both min and max to the current iteration to see if it should be bumped.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•