728x90
▶10991번 문제
▶풀이방법1
import java.util.*;
public class Main{
public static void main(String[] args) {
int num = new Scanner(System.in).nextInt();
for(int i = 0; i < num; i++) {
for(int j = i; j < num-1; j++) {
System.out.print(" ");
}
for(int z = 0; z <= i; z++) {
System.out.print("*");
if(z != i) {
System.out.print(" ");
}
}
System.out.println();
}
}
}
▶풀이방법2
-BufferdReader와 BufferdWriter사용
import java.io.*;
public class Main{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
int num = Integer.parseInt(br.readLine());
String star = "*";
String space = "";
for(int i = 0; i < num; i++) {
star += " *";
space += " ";
}
for(int j = 1; j <= num; j++) {
bw.write(space.substring(0,num-j) + star.substring(0,2*j));
bw.newLine();
}
br.close();
bw.flush();
bw.close();
}
▶10992번 문제
▶풀이방법1
import java.util.*;
public class Main{
static void printStars(int a) {
/*for(int j = 0; j < a; j++) {
if(j != a-1) {
System.out.print(" ");
}else {
System.out.print("*");
}
}*/
System.out.print(j != a-1 ? " " : "*");
}
public static void main(String[] args) {
int num = new Scanner(System.in).nextInt();
for(int i = 0; i < num-1; i++){
printStars(num-i);
printStars(2*i);
System.out.println();
}
for(int i = 0; i < 2*num-1; i++) {
System.out.print("*");
}
}
}
728x90
'Algorithm > BaekJoon[Java]' 카테고리의 다른 글
백준 11726 (0) | 2022.03.19 |
---|---|
백준 1463(Dynamic Programming) (0) | 2022.03.19 |
백준 2438, 2439, 2440, 2441, 2442, 2445, 2446 (별찍기) (0) | 2022.03.17 |
백준 10818 (0) | 2022.03.17 |
백준 8393 (0) | 2022.03.17 |