Im trying to receive 5 products prices and 5 product's names by separates arrays and print at the end, so im correcting the errors till this error appears : Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 5 at javaapplication3.JavaApplication3.main(JavaApplication3.java:23)
thats the final boss for me(sorry about this post being closed)
package javaapplication3;
import java.util.Scanner;
public class JavaApplication3 {
public static void main(String[] args) {
Scanner read = new Scanner(System.in);
double n [] = new double [5];
String name[] = new String[5];
double media;
int contar=0;
for(int counter=0; counter<=n.length; counter++)
{
System.out.println("Type the product "+counter+ " price");
n[counter] = read.nextDouble();
}
for(int i =0; i<=name.length;i++)
{
System.out.println("Type the product "+n[i]+" name");
name[i] = read.nextLine();
}
while(contar<=5)
{
System.out.println(n[contar]);
if(n[contar]<=50)
{
System.out.println("The "+name[contar]+" costs" +n[contar]);
}
media = n [contar]/5;
contar++;
}
}
}