
๐ก ํ๋๋ก ์ ๋ ฅ๋ ๋ฌธ์๋ฅผ ๋ถ๋ฆฌํ์ฌ ์ฐ์ฐ์ ํ ์ ์๋์ง ?
์ซ์๋ฅผ ์ํ์ ์ผ๋ก ํด์ํด์ %์ฐ์ฐ์์ /์ฐ์ฐ์๋ฅผ ์ด์ฉํด ์๋ฅผ ๋ถ๋ฆฌํด ํธ๋ ๋ฐฉ๋ฒ๋ง ์๊ฐํ๋ค. ์์น๋ฅผ ํด๋ณด๋ ์ธ๊ฐ์ง ๋ฐฉ๋ฒ์ด ์์๋ค.
code
import java.util.Scanner;
public class Main{
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%10));
System.out.println(a*(b%100/10));
System.out.println(a*(b/100));
System.out.println(a*b);
}
}

'0' ์ ์๋ฏธ?
์ธ๋ฑ์ค๋ฅผ ์ฐธ์กฐํ ๋ค -'0'์ ํด์ฃผ๋ ์ด์ ๋ ์ฐ๋ฆฌ๊ฐ ๋ฌธ์๋ก ์ ์ฅ๋ ์ซ์๊ฐ ์๋ ์ฐ๋ฆฌ๊ฐ ๋ณด๋ ์ซ์ ๊ทธ๋๋ก์ ๊ฐ์ ์ฐ๊ธฐ ์ํจ์ด๋ค.
์์ ์์๋ฅผ ๋ค์ด ์ค๋ช
ํ์๋ฉด, ์ฐ๋ฆฌ๊ฐ ๋ถ๋ฆฌํ๋ ค๋ ๊ฐ์ 3์ด๋ค. ๊ทธ๋ฌ๋,charAt()ํจ์๋ฅผ ์ด์ฉํ๋ฉด ์์คํค์ฝ๋ ๊ฐ์ธ 51๋ก ๋ถ๋ฌ์ค๊ฒ ๋๋๊ฒ์ด๋ค.
๋ฐ๋ผ์, '0'์ ์ ๋์ฝ๋๊ฐ์ (48) ์ด๋ฏ๋ก, B์ ์ ์ฅ๋๋ ๊ฐ์ 51 - 48 = 3 ์ด ์ ์ฅ๋๋๊ฒ์ด๋ค.
code
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int A = in.nextInt();
String B = in.next();
in.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));
}
}
code
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));
}
}
JAVA API์์์ ์ค๋ช
์ ๋ค์๊ณผ ๊ฐ๋ค.

์ด ๋ฌธ์์ด์ ๋ฌธ์ ๋ฐฐ์ด๋ก ๋ณํํ ๋ค, ๊ฐ ๋ฌธ์๋ฅผ ๋ฐฐ์ด์์ ๊ฐ๋ณ์ ์ผ๋ก ์ ๊ทผํ๊ฑฐ๋ ์ฌ์ฉํ ์ ์๋๋ก ํ๋ค. ์๋ฅผ๋ค์ด, ๋ฌธ์์ด์ ๊ธธ์ด๊ฐ ๊ฐ๋ณ์ ์ผ๋ก ์ ๋ ฅ๋๋ฉฐ ๋ฌธ์ ํ๋์ฉ ์ฐธ์กฐํด์ผํ ๋ ์ ์ฉํ ๋ฉ์๋์ด๋ค.