본문 바로가기
Algorithm

자바 세자리 연산 과정

by ZEROMI 2021. 11. 25.
728x90

백준알고리즘 2588


(1) a = 472, (2) b = 385

기준 값을 10으로 반복해 나눈 값을 10으로 나머지 연산을 하면 일의 자리를 얻을 수 있다.

 

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();
        int tmp = b;
        
        for (int i = 0; i < 3; i++) {
            tmp = (i > 0 ? tmp / 10 : b);
            System.out.println(a * (tmp % 10));
        }
        
        System.out.println(a * b);
        
    }    
}
728x90