문제 설명
이 문제에는 표준 입력으로 두 개의 정수 n과 m이 주어집니다.
별(*) 문자를 이용해 가로의 길이가 n, 세로의 길이가 m인 직사각형 형태를 출력해보세요.
입력 | 입력 |
---|---|
5 | 3 |
*****
*****
*****
import java.util.Scanner;
class Solution {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
int b = sc.nextInt();
System.out.println(a + b);
}
}
import java.util.Scanner;
class Solution {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
int b = sc.nextInt();
for(int i = 1; i <= b; i++){
for(int j = 1; j<= a; j++){
System.out.print("*");
}
System.out.println( );
}
//System.out.println(a + b);
}
}
Scanner를 통해 입력을 받고 행과 열을 출력하기 위해 for문을 2개 써서 *을 찍도록 하였고 반복문이 끝나면 println을 통해 줄 바꿈을 해주는 방법으로 작성했다.