본문 바로가기
카카오x구름 풀스택/코딩 테스트

[JAVA] 별찍기(1) ~ 별찍기(3)

by 꾸주니=^= 2024. 11. 28.

 


 

별찍기 (1)

 

작성한 코드

import java.util.Scanner;
class Main {
	public static void main(String[] args) throws Exception {
		
		Scanner scanner = new Scanner(System.in);
		
		int N = scanner.nextInt(); //세로
		
		for(int i =0; i<N; i++){ //줄 단위의 반복문
			for(int j=0;j<N;j++){
				System.out.print("*");
			}
			System.out.println();
		}
		scanner.close();
	}
}

 

꿀팁

 


별찍기(2)

 

 

작성한 코드

import java.util.Scanner;
class Main {
	public static void main(String[] args) throws Exception {
		
		Scanner scanner = new Scanner(System.in);
		
		//입력을 2개 받아야함
		int N = scanner.nextInt(); //세로(열)
		int M = scanner.nextInt(); //가로(행)
		
		//행, 열 구분 잘하자.
		for(int i =0; i<N; i++){ //세로(열)
			for(int j=0;j<M;j++){ //가로(행)
				System.out.print("*");
			}
			System.out.println();
		}
		scanner.close();
	}
}

 


별찍기(3) 문제 풀어보기

문제 푼 후 꼭 제출하기!