package 별찍기;
import java.util.Scanner;
public class Ex1 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("숫자를 입력하세요");
int num = sc.nextInt();
for(int i=0; i<=num; i++){
for(int j=0; j<=num; j++){
System.out.print("*");
}
System.out.println();
}
}
}
package 별찍기;
import java.util.Scanner;
public class Ex2 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("숫자를 입력하세요");
int num =sc.nextInt();
for(int i=0; i<=num; i++){
for(int j =0; j<i; j++){
System.out.print("*");
}
System.out.println();
}
}
}
package 별찍기;
import java.util.Scanner;
public class Ex3 {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("정수를 입력하세요");
int num =sc.nextInt();
for(int i=0; i<=num; i++){
for(int j=0; j<num-i; j++){
System.out.print(" ");
}
for(int j=0; j<=i; j++){
System.out.print("*");
}
System.out.println();
}
}
}
package 별찍기;
import java.util.Scanner;
public class Ex4 {
public static void main(String[] args) {
Scanner sc= new Scanner(System.in);
System.out.println("정수를 입력하시오.");
int num =sc.nextInt();
for(int i=0; i<num; i++){
for(int j=0; j<num-i; j++){
System.out.print("*");
}
for(int j=0; j<num; j++){ // " " 이것은 있어도 되지만 없어도 무방하다.
System.out.print(" ");
}
System.out.println();
}
}
}
package 별찍기;
import java.util.Scanner;
public class Ex5 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("정수를 입력하시오.");
int num =sc.nextInt();
for(int i=0; i<=num; i++){
for(int j =0; j<=i-1; j++){
System.out.print(" ");
}
for(int j=0; j<=num-i; j++){
System.out.print("*");
}
System.out.println();
}
}
}
package 별찍기;
import java.util.Scanner;
public class Ex6 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("정수를 입려하시오.");
int num = sc.nextInt();
for (int i = 0; i <= num; i++) {
for (int j = 0; j <= i; j++) {
System.out.print("*");
}
System.out.println();
}
for (int i = 0; i <= num - 1; i++) {
for (int j = 0; j <= num - 1 - i; j++) {
System.out.print("*");
}
System.out.println();
}
}
}
package 별찍기;
import java.util.Scanner;
public class Ex7 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("정수를 입력하시오.");
int num =sc.nextInt();
for(int i=0; i<=num; i++){
for(int j=0; j<=num-i; j++){
System.out.print("*");
}
System.out.println();
}
for(int i =0; i<=num-1; i++){
for(int j =0; j<=i+1; j++){
System.out.print("*");
}
System.out.println();
}
}
}
처음에 이거를 할때는 진짜 머리카락이 빠지는줄 알았는데.여전히 어렵네요..계속 반복하면서 응용을 해보자.
package 별찍기;
import java.util.Scanner;
public class Ex8 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("홀수 정수를 입력하세요.");
int num = sc.nextInt();
//상단
for (int i = 1; i <= num; i++) { //i를1로시작하는 이유는 2번째 반복때 2*1-1 할때 0이 되기때문이다.("*")
for (int j = 1; j <= num - i; j++) {
System.out.print(" ");
}
for (int j = 1; j <= 2 * i - 1; j++) {
System.out.print("*");
}
System.out.println();
}
//하단
for (int i = num - 1; i >= 1; i--) {
for (int j = num - 1; j >= i; j--) {
System.out.print(" ");
}
for (int j = 1; j <= 2 * i - 1; j++) {
System.out.print("*");
}
System.out.println();
}
}
}