Is there a way to simplify this code? I tried iterating around just one for loop, converting the loop variable into a String and concatenating it with the variables arreglo2, 3 and 4; but it doesn't work. It doesn't even allow me to concatenate the variables ...

Indice = 0;
System.out.println("\nAge Range from 20 to 29\n");
for ( x = 0 ; x < arreglo2.length ; x++)
{
  indice = x + 1;
  System.out.println(indice + ". " + arreglo2[ x ]);
}
indice = 0;
System.out.println("\nAge Range from 30 to 39\n");
for ( x = 0 ; x < arreglo3.length ; x++)
{
  indice = x + 1;
  System.out.println(indice + ". " + arreglo3[ x ]);
}
indice = 0;
System.out.println("\nAge Range from 40 to 49\n");
for ( x = 0 ; x < arreglo4.length ; x++)
{
  indice = x + 1;
  System.out.println(indice + ". " + arreglo4[ x ]);
}

Thanks a bunch...

int indice = 0;
System.out.println("\nAge Range from 20 to 29\n");
for (String x: arreglo) { System.out.println(++indice + "." + x); }

And similarly for the other loops.
Turn that into a method and call it several times instead of writing it out several times.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.