jeudi 25 décembre 2014

How do I reunite those if conditions in one loop?

i've been trying to loop these if but i don't get it, where do I have to put the loop?



public static void Run(int n) {
int l;
int c;
for (l = 1; l <= 2 * n - 1; l++) {
System.out.println("\n");
for (c = 1; c <= 2 * n - 1; c++) {

if ((l == 1) || (l == 2 * n - 1) || (c == 1) || (c == 2 * n - 1)) {
System.out.print('a');
} else if ((l == 2) || (l == 2 * n - 2) || (c == 2) || (c == 2 * n - 2)) {
System.out.print(defLettre(n, 1));
} else if ((l == 3) || (l == 2 * n - 3) || (c == 3) || (c == 2 * n - 3)) {
System.out.print(defLettre(n, 2));
} else if ((l == 4) || (l == 2 * n - 4) || (c == 4) || (c == 2 * n - 4)) {
System.out.print(defLettre(n, 3));
} else if ((l == 5) || (l == 2 * n - 5) || (c == 5) || (c == 2 * n - 5)) {
System.out.print(defLettre(n, 4));

} else {
System.out.print(" ");
}

}

}

}
}


Thing is, the more n becomes the more if I have to input and i don't get how you reunite them.


Thanks for your help


Aucun commentaire:

Enregistrer un commentaire