Java BigInteger - HackerRank problem

Problem: 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,  and .

Constraints

 and  are non-negative integers and can have maximum  digits.

Output Format

Output two lines. The first line should contain , and the second line should contain . Don't print any leading zeros.

Sample Input

1234
20

Sample Output

1254
24680
 Solution:
import java.io.*;
import java.util.*;
import java.util.Scanner;
import java.math.BigInteger;

public class Solution {

    public static void main(String[] args) {
        
        Scanner sc = new Scanner (System.in);
        BigInteger num1= new BigInteger(sc.next());
        BigInteger num2= new BigInteger(sc.next());
        BigInteger num3,num4;
        
        num3=num1.add(num2);
        num4=num1.multiply(num2);
        
        System.out.println(num3);
        System.out.println(num4);
        
    }
}


//Thank You
//Aurnab Das

Post a Comment

Previous Post Next Post