I have enter image description here tried but not getting close, unable to get the relation between rows and columns to run the loop.`
static void makeRhombus(int rows) { int i, j; int horizontal = 2 * rows; int vertical = rows + 1; for (i = 1; i <= vertical; i++) { /* Print trailing spaces */ for (j = 1; j <= rows + 1 - i; j++) { System.out.print(" "); } /* Print stars and center spaces */ for (j = 1; j <= 2 * rows; j++) { if (i != 1 && j == 1 || j == horizontal && i != 1) { System.out.print("/"); } else if (i == vertical || i == 1) { System.out.print("_"); } else if (i == vertical && j == 1) { System.out.print("/"); } else { System.out.print(" "); } } System.out.print("\n"); } } https://stackoverflow.com/questions/66713113/how-to-print-given-rhombus-in-attached-image-with-same-logic-in-java-or-any-othe March 20, 2021 at 01:41AM
没有评论:
发表评论