Hello again,
dieses mal lautet meine Aufgabe ein Schachbrettartiges gerüst folgendermaßen in der Eclipse-konsole auszugeben:
A1 A2 A3 A4 A5 A6 A7 A8
B1 B2 B3 B4 B5 B6 B7 B8
C1 C2 C3 C4 C5 C6 C7 C8
D1 D2 D3 D4 D5 D6 D7 D8
E1 E2 E3 E4 E5 E6 E7 E8
F1 F2 F3 F4 F5 F6 F7 F8
G1 G2 G3 G4 G5 G6 G7 G8
H1 H2 H3 H4 H5 H6 H7 H8
Ich habe dies folgendermaßen gelöst:
Das ist schon noch recht umfangreich und eigentlich glaub ich nicht ganz die richtige Lösung, trotz korrekter ausgabe. Ich sollte es lösen mit 2 geschachtelten schleifen.
Kann mir da jemand weiterhelfen?
dieses mal lautet meine Aufgabe ein Schachbrettartiges gerüst folgendermaßen in der Eclipse-konsole auszugeben:
A1 A2 A3 A4 A5 A6 A7 A8
B1 B2 B3 B4 B5 B6 B7 B8
C1 C2 C3 C4 C5 C6 C7 C8
D1 D2 D3 D4 D5 D6 D7 D8
E1 E2 E3 E4 E5 E6 E7 E8
F1 F2 F3 F4 F5 F6 F7 F8
G1 G2 G3 G4 G5 G6 G7 G8
H1 H2 H3 H4 H5 H6 H7 H8
Ich habe dies folgendermaßen gelöst:
Java:
public static void main(String[] args) {
int x=8;
int z=1;
int a=0;
int b=0;
int c=0;
int d=0;
int e=0;
int f=0;
int g=0;
int h=0;
for (;z<=x;){
z++;
while (a<=x){
a++;
if (a<x){
System.out.print("A"+a+" ");}
if (a==x){
System.out.println("A"+a);}
}
while (b<=x){
b++;
if (b<x){
System.out.print("B"+b+" ");}
if (b==x){
System.out.println("B"+b);}}
while (c<=x){
c++;
if (c<x){
System.out.print("C"+c+" ");}
if (c==x){
System.out.println("C"+c);}}
while (d<=x){
d++;
if (d<x){
System.out.print("D"+d+" ");}
if (d==x){
System.out.println("D"+d);}}
while (e<=x){
e++;
if (e<x){
System.out.print("E"+e+" ");}
if (e==x){
System.out.println("E"+e);}}
while (f<=x){
f++;
if (f<x){
System.out.print("F"+f+" ");}
if (f==x){
System.out.println("F"+f);}}
while (g<=x){
g++;
if (g<x){
System.out.print("G"+g+" ");}
if (g==x){
System.out.println("G"+g);}}
while (h<=x){
h++;
if (h<x){
System.out.print("H"+h+" ");}
if (h==x){
System.out.println("H"+h);}}
}
}
}
Kann mir da jemand weiterhelfen?