나의 풀이 - 이중for문 j를 감소시키는 방향으로
import java.util.Scanner;
public class Solution {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
for(int i=1; i<n+1; i++){
for(int j=i; j+1>1; j--){
System.out.print("*");
}
System.out.println();
}
}
}
다른 사람의 풀이1 - 파이썬풀이와 유사-repeat(반복횟수)
import java.util.Scanner;
public class Solution {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
for(int i=1; i<=n; i++){
System.out.println("*".repeat(i));
}
}
}
다른 사람의 풀이2 - 이중 for문 j를 증가시키는 방향으로
import java.util.Scanner;
public class Solution {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
for(int i=0; i<n; i++){
for(int j=0; j<=i; j++){
System.out.print("*");
}
System.out.println();
}
}
}
'프로그래머스(자바) > LV.0(자바)' 카테고리의 다른 글
문자열 정렬하기(2) - String클래스의 toCharArray() (0) | 2022.11.24 |
---|---|
문자열 정렬하기(1) - replaceAll(), Stream(), mapToInt() (0) | 2022.11.24 |
역삼각형 출력하기-★별찍기 (0) | 2022.11.24 |
모음제거 → String 클래스 →contains(), replaceAll()★ + 정규식★ (0) | 2022.11.22 |
옷가게 할인 받기 - return시 int형으로 타입 맞추기 (0) | 2022.11.22 |