所以,当我做块的代码在一个"尝试{}",我尝试返回一个值,它出来"没有返回值".这是我使用的代码,代表我的问题.
import org.w3c.dom.ranges.RangeException;
public class Pg257E5
{
public static void main(String[]args)
{
try
{
System.out.println(add(args));
}
catch(RangeException e)
{
e.printStackTrace();
}
finally
{
System.out.println("Thanks for using the program kiddo!");
}
}
public static double add(String[] values) // shows a commpile error here that I don't have a return value
{
try
{
int length = values.length;
double arrayValues[] = new double[length];
double sum =0;
for(int i = 0; i<length; i++)
{
arrayValues[i] = Double.parseDouble(values[i]);
sum += arrayValues[i];
}
return sum; …Run Code Online (Sandbox Code Playgroud)