Advertisement
deyanmalinov

05. Multiply Big Number

Mar 25th, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.87 KB | None | 0 0
  1. package DPM;
  2.  
  3. import java.util.*;
  4.  
  5. public class Main {
  6.     public static void main(String[] args) {
  7.         Scanner scan = new Scanner(System.in);
  8.         String num = scan.nextLine();
  9.         int mult = Integer.parseInt(scan.nextLine());
  10.         if (mult==0){
  11.             System.out.println(0);
  12.         }else {
  13.             int rem = 0;
  14.             List<Integer> result = new ArrayList<>();
  15.             for (int i = num.length()-1; i >=0; i--) {
  16.                 int res = (num.charAt(i) -'0') * mult;
  17.                 res += rem;
  18.                 rem = res / 10;
  19.                 result.add(res % 10);
  20.             }
  21.             if (rem != 0){
  22.                 result.add(rem);
  23.             }
  24.             for (int i = result.size()-1; i >=0 ; i--) {
  25.                 System.out.print(result.get(i));
  26.  
  27.             }
  28.             System.out.println();
  29.         }
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement