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.


hackerrank java biginteger solution


Java BigInteger problem solution | HackerRank

import java.math.*;
import java.util.Scanner;
public class Solution {
   public static void main(String []args){
       Scanner input = new Scanner(System.in);
       String s1,s2;
       s1=input.nextLine();
       s2=input.nextLine();
       input.close();
       System.out.println(new BigInteger(s1).add(new BigInteger(s2)));
       System.out.println(new BigInteger(s1).multiply(new BigInteger(s2)));
   }
}

Second solution

import java.math.BigInteger;

public class Main {
  public static void main(String args[]) {
    BigInteger b1= new BigInteger("1000000000000");
    BigInteger b2= new BigInteger("1");
    
    // b1.add(b2) returns the sum of b1 and b2
    // store the sum in b1
    b1=b1.add(b2);
    
    //printing the sum of original b1 and b2 
    System.out.println(b1);
  }
}

Third solution

import java.math.BigInteger;

public class Main {
  public static void main(String[] argv) throws Exception {
    BigInteger b1 = new BigInteger("1234567890123456890");
    BigInteger b2 = new BigInteger("45");
	
    // b1.multiply(b2) returns the product of b1 and b2
    // store the product in b1
    b1 = b1.multiply(b2);
    
    //printing the product
    System.out.println(b1);
  }
}