본문 바로가기
(Pre-class)

Star Pattern exercise

by coramdeo643 2025. 4. 3.
//    *
//   **
//  ***
// ****
for (int a = 4; a > 0; a--) {
  for (int b = 1; b < a; b++) {
    System.out.print(" ");
  } 
  for (int c = a; c < 5; c++) {
    System.out.print("*");
  }
  System.out.println();
}
//    * 
//   * * 
//  * * * 
// * * * * 
//  * * * 
//   * * 
//    * 
for (int a = 4; a > 0; a--) {
  for (int b = 1; b < a; b++) {
    System.out.print(" ");
  }
  for (int c = a; c < 5; c++) {
    System.out.print("* ");
  }
  System.out.println();
} 
for (int a = 4; a > 0; a--) {
  for (int c = a; c < 5; c++) {
    System.out.print(" ");
  }
  for (int i = 1; i < a; i++) {
    System.out.print("* ");
  } 
  System.out.println();
}

'(Pre-class)' 카테고리의 다른 글

Nested for loops exercise  (0) 2025.04.03
Do-while loop?  (0) 2025.04.03
For - If exercise  (0) 2025.04.03
Break and Continue?  (0) 2025.04.02
While loop?  (0) 2025.04.02