[Java] 알고리즘 문제풀이
[CodeUp / java] 1371 : 마름모 출력하기
sweetychocoding
2023. 9. 21. 09:16
728x90
package example01;
import java.util.Scanner;
public class Ex05_Chapter7 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int st, ed;
for (int i = 1; i <= n * 2; i++) {
if (i <= n) {
st = (n + 1) - i;
ed = n + i;
} else {
st = i - n;
ed = 16 - i;
}
for (int j = 1; j <= ed; j++) {
if (j == st || j == ed) {
System.out.print("*");
} else {
System.out.print(" ");
}
}
System.out.println();
}
}
}
.... 하찮은 나의 코드....!
내 코드는 n=5일 때 한정이다~ 야호~
더 생각을 해봐야지... 그래야겠지...
하하 별찍기 참으로 재밌구나 (구라)
더 생각하고 올게요! (아직 16의 의미를 생각해내지 못했어..........흑흑)
+성공 (20230922)
package j17_Lambda;
import java.util.Scanner;
public class Ex_chapter9 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int st, ed;
int s = 1;
for (int i = 1; i <= n * 2; i++) {
if (i <= n) {
st = (n + 1) - i;
ed = n + i;
} else {
st = i - n;
ed = n - s + i;
s+=2;
}
for (int j = 1; j <= ed; j++) {
if (j == st || j == ed) {
System.out.print("*");
} else {
System.out.print(" ");
}
}
System.out.println();
}
}
}728x90