Ich versuche, einen Diamanten mit * und "o" in der Mitte mit Do While-Schleife zu drucken. Ich habe das schon mit der For-Schleife gemacht, aber ich bin mir nicht sicher, wie ich es in die while-Schleife ändern kann. Kann jemand etwas Unterstützung geben?Drucken eines Diamanten mit * und "o" in der Mitte mit Do While-Schleife in Java
public static void diamond1() {
System.out.println("Diamond Height: " + DIAMOND_SIZE);
System.out.println("Output for: For Loop");
int noOfRows = DIAMOND_SIZE;
//Getting midRow of the diamond
int midRow = (noOfRows)/2;
//Initializing row with 1
int row = 1;
//Printing upper half of the diamond
for (int i = midRow; i > 0; i--)
{
//Printing i spaces at the beginning of each row
for (int j = 1; j <= i; j++) {
System.out.print(" ");
}
//Printing j *'s at the end of each row
for (int j = 1; j <= row; j++) {
System.out.print("* ");
}
System.out.println();
//Incrementing the row
row++;
}
//Printing lower half of the diamond
for (int i = 0; i <= midRow; i++) {
//Printing i spaces at the beginning of each row
for (int j = 1; j <= i; j++) {
System.out.print(" ");
}
//Printing j *'s at the end of each row
int mid = (row+1)/2;
for (int j = row; j > 0; j--) {
if(i==0 && j==mid) {
System.out.print("o ");
}
else {
System.out.print("* ");
}
}
System.out.println();
//Decrementing the row
row--;
}
}
Wie würde ich das machen?
Sie sollten mit Ihrem Mitschülern zusammenarbeiten ... Blick auf [seine Frage] (http://stackoverflow.com/questions/42179756/printing-diamonds-using -Stars-und-o-in-Java # Kommentar71522651_42179756). – QBrute