Please can someone advise me, how I could use a loop for this code, in the interests of code reuse.
My code is as follows
public class Clubs{
public void printGreeting(int choice, String clubName[]) {
System.out.println("\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
if (choice==1){
System.out.println("You chose: " + clubName[0]);
}
if (choice==2){
System.out.println("You chose: " + clubName[1]);
}
if (choice==3){
System.out.println("You chose: " + clubName[2]);
}
if (choice==4){
System.out.println("You chose: " + clubName[3]);
}
if (choice==5){
System.out.println("You chose: " + clubName[4]);
}
if (choice==6){
System.out.println("You chose: " + clubName[5]);
}
if (choice==7){
System.out.println("You chose: " + clubName[6]);
}
if (choice==8){
System.out.println("You chose: " + clubName[7]);
}
if (choice==9){
System.out.println("You chose: " + clubName[8]);
}
if (choice==10){
System.out.println("You chose: " + clubName[9]);
}
if (choice==11){
System.out.println("You chose: " + clubName[10]);
}
if (choice==12){
System.out.println("You chose: " + clubName[11]);
}
if (choice==13){
System.out.println("You chose: " + clubName[12]);
}
if (choice==14){
System.out.println("You chose: " + clubName[13]);
}
if (choice==15){
System.out.println("You chose: " + clubName[14]);
}
if (choice==16){
System.out.println("You chose: " + clubName[15]);
}
if (choice==17){
System.out.println("You chose: " + clubName[16]);
}
if (choice==18){
System.out.println("You chose: " + clubName[17]);
}
if (choice==19){
System.out.println("You chose: " + clubName[18]);
}
if (choice==20){
System.out.println("You chose: " + clubName[19]);
}
}
}
clubName
? Full code is more welcome than partial – Caridorc yesterdaySystem.out.println("You chose: " + clubName[choice - 1]);
? – TopinFrassi yesterday