1
I’m creating a method to catch n values, adding them in an array, and from these values apply the Lagrange interpolation method to find a polynomial. Soon after, find an estimated value of x for the range defined by the largest and smallest value of the inputted data set.
It’s just that you’re making a mistake in while, because he even takes the first value, but when he goes through the first instruction of input he gives the following:
- ERROR:
Exception in thread "main" java.lang.Arrayindexoutofboundsexception: 0
at Lagrange.calculate(Lagrange.java:13)
At Main.main(Main.java:6)
Exit status 1
import java.util.Scanner;
public class lagrange{
public void calculate(){
Scanner sc = new Scanner(System.in);
double n[];
int cont = 0;
do {
n = new double[cont];
System.out.println("Digite o valor de numero " + cont + 1);
n[cont] = sc.nextDouble(); //INPUT DE DADO NO ARRAY
cont = cont + 1;
} while(n[cont - 1] != 0); //continuar o processo até o array for igual a zero
System.out.println(n[cont-1]);
}
}