Java BigInteger-HackerRank Solution

0

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 type like a long integer.


Difficulty :      Easy

Max Score :   10




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 .


Constraints


 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*b. Don't print any leading zeros.


Sample Input



 1234
 20


Sample output

 


 1254
 24680


Explanation

1234 + 20 = 1254
1234 * 20 = 24680

Solution 

 import java.io.*;
 import java.util.*;
 import java.math.BigInteger;

 public class Solution {

 public static void main(String[] args) {

 Scanner scan = new Scanner(System.in);
 BigInteger a = new BigInteger(scan.next());
 BigInteger b = new BigInteger(scan.next());
 System.out.println(a.add(b));
 System.out.println(a.multiply(b));
  }
 }



What is Big Integer

BigInteger class is used for the mathematical operation which involves very big integer calculations that are outside the limit of all available primitive data types.

Post a Comment

0 Comments
* Please Don't Spam Here. All the Comments are Reviewed by Admin.
Post a Comment (0)
Our website uses cookies to enhance your experience. Learn More
Accept !