Kent_St_1

Untitled

Jul 23rd, 2021
955
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.Scanner;
  2.  
  3. public class MultiplyBigNumber_05_Exercises {
  4.     public static void main(String[] args) {
  5.         Scanner scan = new Scanner(System.in);
  6.        String bigNumber = scan.nextLine();
  7.        int number = Integer.parseInt(scan.nextLine());
  8.        if(number == 0) {
  9.            System.out.println(0);
  10.            return;
  11.        }
  12.        while (bigNumber.charAt(0) == '0') {
  13.            bigNumber = bigNumber.substring(1);
  14.        }
  15.        StringBuilder builder = new StringBuilder();
  16.        int result = 0;
  17.        int reminder = 0;
  18.         for (int i = bigNumber.length() -1; i >= 0 ; i--) {
  19.             int currentDigit = Integer.parseInt(String.valueOf(bigNumber.charAt(i)));
  20.             result = currentDigit * number + reminder;
  21.             reminder = 0;
  22.             if (result > 9) {
  23.                 reminder = result / 10;
  24.                 result = result % 10;
  25.             }
  26.             builder.append(result);
  27.         }
  28.         if (reminder != 0) {
  29.             builder.append(reminder);
  30.         }
  31.         System.out.print(builder.reverse());
  32.     }
  33. }
  34.  
RAW Paste Data