So I have this code, where en1 is an instance of a object.
for (int i = 0; i < 20; i++) {
System.out.println("Introduce el nombre de una empresa");
Scanner scanner = new Scanner(System.in);
en1.setName(scanner.next());
}
I would like to change the 1 on en1 to the loop counter. Is this possible?
Your best bet is to use an Array and have each element correspond to the iteration of the loop.
The array in my example will have 20 elements (0 through 19). Each one can correspond to a single iteration. There is no way to change the name of a variable based on other variables.