This is the code that I made.... for the array code
public class main
{
public static int arraySum(int[] arr)
{
int result = 0;
for (int i = 0; i < arr.length; i++)
{
result += arr[i];
}
return result;
}
public static int arraySumBetter(int [] a)
{
int result = 0;
for (int value : a)
{
result += value;
}
return result;
}
public static void main(String [] args)
{
double[] a ={0,2,3,1,0.56};
System.out.format("%.1f", (double) arraySumBetter(a));
}
}
when I run it it prints an error out:
typed.java:25: error: incompatible types: double[] cannot be converted to int[] System.out.format("%.1f", (double) arraySumBetter(a));
Note: Some messages have been simplified; recompile with -Xdiags:verbose to get full output1 error
I thought to add decimal numbers using double would be work but it didn't work.. Is there any way to fix this? I would appreciate any tips... thanks...