la-ma-rin

multiplyBigNumber

Mar 27th, 2019
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.85 KB | None | 0 0
  1. import java.util.ArrayList;
  2. import java.util.List;
  3. import java.util.Scanner;
  4.  
  5. public class multiplyBigNumbers {
  6.     public static void main(String[] args) {
  7.         Scanner scan = new Scanner(System.in);
  8.  
  9.         String input = scan.nextLine();
  10.         int n = Integer.parseInt(scan.nextLine());
  11.  
  12.         List<Integer> output = new ArrayList<>();
  13.  
  14.         int b = 0;
  15.  
  16.         if (n == 0){
  17.             System.out.println(0);
  18.             return;
  19.         }
  20.  
  21.         for (int i = input.length() - 1; i >= 0; i--) {
  22.  
  23.             int a = Character.getNumericValue(input.charAt(i)) * n + b;
  24.             b = a / 10;
  25.             int c = a % 10;
  26.  
  27.             output.add(0, c);
  28.         }
  29.  
  30.         if (b != 0) {
  31.             output.add(0, b);
  32.         }
  33.  
  34.         for (Integer integer : output) {
  35.             System.out.print(integer);
  36.         }
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment