HackerRank 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.

  1. import java.io.*;
  2. import java.util.*;
  3. import java.text.*;
  4. import java.math.*;
  5. import java.util.regex.*;
  6. public class Solution {
  7. public static void main(String[] args) {
  8. Scanner scan = new Scanner(System.in);
  9. BigInteger x = new BigInteger(scan.next());
  10. BigInteger y = new BigInteger(scan.next());
  11. System.out.println(x.add(y));
  12. System.out.println(x.multiply(y));
  13. }
  14. }

download android app