Algorithm
Problem Name:
In this HackerRank Functions in Java programming problem solution,
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.
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
Code Examples
#1 Code Example with Java Programming
Code -
Java Programming
import java.math.BigInteger;
import java.util.Scanner;
public class Solution {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
String a = input.nextLine();
String b = input.nextLine();
input.close();
System.out.println(new BigInteger(a).add(new BigInteger(b)));
System.out.println(new BigInteger(a).multiply(new BigInteger(b)));
}
}
Copy The Code &
Try With Live Editor