백준 2588(곱셈)

한장민·2022년 5월 14일
0
post-thumbnail

https://www.acmicpc.net/problem/2588

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

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());
		int b = Integer.parseInt(br.readLine());
		
		
		
		int c = a * (b%10);
		int d = a * ((b%100)/10);
		int e = a * (b/100);
		System.out.println(c);
		System.out.println(d);
		System.out.println(e);
		System.out.println(e * 100 + d * 10 + c);
		
		
		

	}

}

정수형 변수 c, d, e를 지정하면서 ()처리를 제대로 해주지 않아서 결과가 이상하게 나왔다. 연산순서를 잘 신경써야겠다. 내가 생각한 방식말고 다른 방법으로 c, d, e를 구할 수 있는지 궁금하다.

profile
HAAN YJGB

0개의 댓글