728x90
<몰랐던 부분>
1. Scanner 로 받는 것보다 BufferedRead, BufferedWrite로 하는 것이 훨씬 빠르다 >> 공부하기로 함
2. num4 를 구할때 ((rand2%100)/10 이 부분을 어려워했다.
3. Scanner 도 sc.close() 형식으로 닫아주기(이클립스에서는 자동으로 닫아준다)
<새로운 풀이>
1. charAt() : 문자(위치)로 끊는 것 : 주의점 , -'0' 을 해주는 이유 또한 우리가 문자로 저장된 숫자가 아닌 우리가 보는 숫자 그대로의 값을 쓰기 위한 것이다.(아직, 이부분에 대한 이해가 부족)
import java.util.Scanner;
class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int A = sc.nextInt();
String B = sc.next();
sc.close();
System.out.println(A * (B.charAt(2) - '0'));
System.out.println(A * (B.charAt(1) - '0'));
System.out.println(A * (B.charAt(0) - '0'));
System.out.println(A * Integer.parseInt(B));
}
}
2. array를 쓰는 방법 : 이건 신기했다, 그냥 한번씩 훑기
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int A = Integer.parseInt(br.readLine());
String B = br.readLine();
char[] b = B.toCharArray();
System.out.println(A * (b[2]-'0'));
System.out.println(A * (b[1]-'0'));
System.out.println(A * (b[0]-'0'));
System.out.println(A * Integer.parseInt(B));
}
}
<도움>
1
자바 특수문자, 괄호, 백슬래시, 따옴표 출력하기 (백준 10171, 10172번)
자바에서 백슬래시와 따옴표는 문자 그 자체만으로는 출력되지 않는 특수문자이다. 따옴표가 그 자체만으로 출력되지 않는 이유는, 출력문에서는 첫 쌍따옴표부터 그 다음 쌍따
chloe-ki.tistory.com
2
[백준] 2588번 : 곱셈 - JAVA [자바]
https://www.acmicpc.net/problem/2588 2588번: 곱셈 첫째 줄부터 넷째 줄까지 차례대로 (3), (4), (5), (6)에 들어갈 값을 출력한다. www.acmicpc.net 문제 매우 간단한 문제다! 3개의 풀이 방법을 제시한다. 이..
st-lab.tistory.com
'Algorithm' 카테고리의 다른 글
[CodeUp / Python] 비트연산 관련 정리(56, 59, 60, 61) (0) | 2022.04.01 |
---|---|
[CodeUp/ Python] 6020 ~ 6042 중 모르던 것, 헷갈린거 정리(20, 23, 27, 29, 30, 31, 32, 33, 34, 35, 42) (0) | 2022.03.30 |
[백준 10171, java] 고양이 (0) | 2021.07.26 |