1
I am making a code where the user needs to define a vector of size N, and fill it, however, after informing the vector size, and informing the first value, the following error appears:
Exception in thread "main" java.lang.Arrayindexoutofboundsexception: 0 tp01.Programex1.main(Programex1.java:22)
Follow the code below:
public static void main(String[] args) {
int tamanhoVetor = 0;
int i;
float vet[] = new float[tamanhoVetor];
Scanner sc = new Scanner(System.in);
System.out.println("Informe o tamanho do vetor desejado: ");
tamanhoVetor = sc.nextInt();
for (i = 0;i<=tamanhoVetor;i++)
{
System.out.printf("Informe o valor: ");
vet[i] = sc.nextFloat();
}
Problem solved, very sheltered by friendly help.
– Kirk