0

Hello I've a error code in java while I try to run this program it states cannot find symbol but I declared everything and Idk what's going on.

import java.util.Scanner;
public class Programa {
    public static void main(String[] args) {  
    String arreglo[];
    Scanner dato=new Scanner(System.in);
    arreglo = new String[10];
    for(int a=1;a<10;a++){
        System.out.printf("Dale el nombre de la persona:");
        arreglo[a]=dato.nextLine();
        }

for (int a=1;a<10;a++){
        System.out.printf("%s%8s\n", a,arreglo(a));
        }
    }
}

This is on the variable arreglo(a)

1 Answers1

-1

Because, you are using () to access array values, you must use [] for arrays:

import java.util.Scanner;
public class Programa {
    public static void main(String[] args) {
        String arreglo[];
        Scanner dato=new Scanner(System.in);
        arreglo = new String[10];
        for(int a=1;a<10;a++){
            System.out.printf("Dale el nombre de la persona:");
            arreglo[a]=dato.nextLine();
        }

        for (int a=1;a<10;a++){
            System.out.printf("%s%8s\n", a,arreglo[a]);
        }
    }
}
Doston
  • 579
  • 6
  • 15