https://www.notion.so/33ca624f1b088037a909c0c743cc62ed
객체지향프로그래밍의 특징 | Notion
객체지향?
www.notion.so
2444 - 별 찍기-7
https://www.acmicpc.net/problem/2444
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int n = s.nextInt();
int cnt = n-1;
int cnt2 = 1;
//증가
for(int i = 1; i<n; i++) {
for(int j = 0; j<cnt; j++) {
System.out.print(" ");
}
for(int j = 0; j<cnt2; j++) {
System.out.print("*");
}
cnt--;
cnt2+=2;
System.out.println("");
}
//가운데
for(int i = 0; i<(2*n-1); i++) {
System.out.print("*");
}
System.out.println("");
//cnt = 1
//cnt2 = 7
//감소
cnt++;
cnt2-=2;
for(int i = 1; i<n; i++) {
for(int j = 0; j<cnt; j++) {
System.out.print(" ");
}
for(int j = 0; j<cnt2; j++) {
System.out.print("*");
}
cnt++;
cnt2-=2;
System.out.println("");
}
}
}
2445 - 별 찍기-8
https://www.acmicpc.net/problem/2445
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int n = s.nextInt();
for(int i = 1; i<=n; i++) {
for(int j = 1; j<=i; j++) {
System.out.print("*");
}
for(int k = 1; k<=2*(n-i); k++) {
System.out.print(" ");
}
for(int j=1; j<=i; j++) {
System.out.print("*");
}
System.out.println();
}
for(int i=n-1; i>0; i--) {
for(int j=1; j<=i; j++) {
System.out.print("*");
}
for(int k=1; k<=2*(n-i); k++) {
System.out.print(" ");
}
for(int j=1; j<=i; j++) {
System.out.print("*");
}
System.out.println();
}
s.close();
}
}
import java.util.Scanner;
public class Main {
//static 함수를 선언할 수도 있음(객체 생성 생략)
public void asta(int i) {
for(int j=1; j<=i; j++) {
System.out.print("*");
}
}
public void spac(int i, int n) {
for(int k = 1; k<=2*(n-i); k++) {
System.out.print(" ");
}
}
public static void main(String[] args) {
Main m = new Main();
Scanner s = new Scanner(System.in);
int n = s.nextInt();
for(int i = 1; i<=n; i++) {
m.asta(i);
m.spac(i,n);
m.asta(i);
System.out.println();
}
for(int i=n-1; i>0; i--) {
m.asta(i);
m.spac(i,n);
m.asta(i);
System.out.println();
}
s.close();
}
}
10811 - 바구니 뒤집기
https://www.acmicpc.net/problem/2445
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int n = s.nextInt();
int m = s.nextInt();
int[] ary = new int[n+1]; //0번째는 안쓴다
for(int k=1; k<=n; k++) {
ary[k] = k;
}
for(int k=1; k<=m; k++) {
int i = s.nextInt();
int j = s.nextInt();
//역순
while(i<j) {
int dummy = ary[i];
ary[i] = ary[j];
ary[j] = dummy;
i++;
j--;
}
}
for(int k = 1; k<=n; k++) {
System.out.print(ary[k]+" ");
}
s.close();
}
}
10991. 별 찍기 - 16
https://www.acmicpc.net/problem/10991
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int n = s.nextInt();
int count = n;
for (int i=1; i<=n; i++) {
for (int j=1; j<count; j++) {
System.out.print(" ");
}
for (int j=1; j<=i; j++) {
System.out.print('*' + " ");
}
System.out.println();
count --;
}
}
}'PROGRAMMING > [java] Baekjoon Online Judge (BOJ)' 카테고리의 다른 글
| [java/BOJ] sw코딩멘토링 - 2480, 2884, 10813 (0) | 2026.03.31 |
|---|---|
| [Java/Baekjoon] 백준 11720번(5-5) : 숫자의 합 (0) | 2025.07.10 |
| [Java/Baekjoon] 백준 11654번(5-4) : 아스키 코드 (0) | 2025.07.09 |
| [Java/Baekjoon] 백준 10951번(3-12) : A+B-4 (0) | 2025.07.03 |
| [Java/Baekjoon] 백준 15552번(3-6) : 빠른 A+B (0) | 2025.07.01 |