You can also check the data before calling the function.
package calculadora;
import java.util.Scanner;
public class Calculadora {
public static void main(String[] args) {
double valor1;
double valor2;
if (args.length == 2) {
valor1 = Double.parseDouble(args[0]);
valor2 = Double.parseDouble(args[1]);
} else {
Scanner scanner = new Scanner(System.in);
System.out.print("Digite o primeiro valor: ");
valor1 = scanner.nextDouble();
System.out.print("Digite o segundo valor: ");
valor2 = scanner.nextDouble();
}
somar(valor1, valor2);
}
private static void somar(double valor1, double valor2) {
System.out.println(valor1 + valor2);
}
}
In the case here, I programmed to request the data for the user, in case they have not been informed in the program call. You could also show an error message, at last are several options.
This answers your question? Why it occurs and how to resolve an error of "out of Bounds" or "out of range" or something of type?
– Piovezan