본문 바로가기

[BOJ] - JAVA

[백준] 2439 : 별 찍기 - 2 JAVA 풀이

제일 처음 짠 코드
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class Main{
    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int T = Integer.parseInt(br.readLine());
        
        for(int i=1;i<=T;i++){
            for(int j=0;j<T-i;j++){
                System.out.printf(" ");
            }
            for(int k=1;k<=i;k++){
                System.out.printf("*");
            }
            System.out.println();
        }
        br.close();
    }
}

 

다른 블로그를 참고해서 다시 짠 코드

https://st-lab.tistory.com/36

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.BufferedWriter;
import java.io.OutputStreamWriter;
import java.io.IOException;

public class Main{
    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
        int T = Integer.parseInt(br.readLine());
        
        for(int i=1;i<=T;i++){
            for(int j=0;j<T-i;j++){
                bw.write(' ');
            }
            for(int k=1;k<=i;k++){
                bw.write('*');
            }
            bw.newLine();
        }
        br.close();
        bw.flush();
        bw.close();
    }
}