Java BigInteger | HackerRank Solution

Hello coders, today we are going to solve Java BigInteger HackerRank Solution.

Java BigInteger


In this problem, you have to add and multiply huge numbers! These numbers are so big that you can’t contain them in any ordinary data types like a long integer.

Use the power of Java’s BigInteger class and solve this problem.

Input Format

There will be two lines containing two numbers, a and b.


a and b are non-negative integers and can have maximum 200 digits.

Output Format

Output two lines. The first line should contain a + b, and the second line should contain a x b. Don’t print any leading zeros.

Sample Input


Sample Output



1234 + 20 = 1254

1234 x 20 = 24680

Solution – Java BigDecimal

import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;

public class Solution {

    public static void main(String[] args) {
        /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
        Scanner sc = new Scanner(;
        BigInteger a = new BigInteger(sc.nextLine());
        BigInteger b = new BigInteger(sc.nextLine());
         BigInteger sum = a.add(b);
          BigInteger prod = a.multiply(b);

Disclaimer: The above Problem ( Java BigInteger ) is generated by Hacker Rank but the Solution is Provided by CodingBroz. This tutorial is only for Educational and Learning Purpose.

Leave a Comment

Your email address will not be published. Required fields are marked *