Preparing Coding Test/Programmers L1
[Java] 직사각형 별찍기
weero
2020. 7. 28. 18:40
문제
https://programmers.co.kr/learn/courses/30/lessons/12969
참고
1. java.util.Scanner
- 표준입력 클래스
- Scanner 변수명 = new Scaner(System.in);
- System.in : 표준 입력 스트림
- nextBoolean();
- nextByte();
- nextShort();
- nextInt();
- nextLong();
- nextFloat();
- nextDouble();
특정 데이터 유형의 값을 읽는 함수 (한 문자를 입력 받는 Scanner 클래스의 메소드는 없음)
- nextLine();
문자열, 한 줄(라인개행 기준)을 모두 읽는 함수
모든 공백을 입력받는다. → 한 줄 단위로 입력되며, Enter키 입력 전까지를 한 문자열로 취급한다.
- next();
공백을 입력받지 않는다. → 한 단어 단위로 입력된다.
- next().charAt(0);
단일 문자(char)를 읽는 함수
- hasNextInt();
- hasNextDouble();
- hasNextLong();
원하는 만큼 입력 받는 함수
- close();
객체와 키보드의 연결 해제
import java.util.Scanner;
public class myScanner
{
public static void main(String[] args)
{
// Scanner 클래스의 객체 생성
Scanner scanner = new Scanner(System.in);
int i = 0;
while(scanner.hasNextInt())
{
int num = scanner.nextInt();
i += num;
}
System.out.println("total : " + i);
// 키보드와의 연결 해제
in.close();
}
}
코드
import java.util.Scanner;
public 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=0; i<b; i++){
for(int j=0; j<a; j++){
System.out.print("*");
}
System.out.println();
}
}
}