Skip to main content

Featured

say hello world with C++ - Solution in Hacker Rank - hackerranksolutions8

  Objective This is a simple challenge to help you practice printing to  stdout . You may also want to complete  Solve Me First  in C++ before attempting this challenge. We’re starting out by printing the most famous computing phrase of all time! In the editor below, use either  printf  or  cout  to print the string  Hello ,World!  to  stdout . The more popular command form is  cout . It has the following basic form: cout<<value_to_print<<value_to_print; Any number of values can be printed using one command as shown. The  printf  command comes from C language. It accepts an optional format specification and a list of variables. Two examples for printing a string are: printf("%s", string);   printf(string); Note that neither method adds a newline. It only prints what you tell it to. Output Format Print   Hello ,World!   to stdout. Sample Output Hello, World! Solution:- //Say Hello, ...

Java BigInteger HackerRank Solution

 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,  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.text.*;


import java.math.*;


import java.util.regex.*;



public class Solution {



    public static void main(String[] args) {



     Scanner sc = new Scanner(System.in);


     BigInteger bi1 = new BigInteger(sc.next());


     BigInteger bi2 = new BigInteger(sc.next());



        BigInteger  bi3, bi4;


        bi3 = bi1.add(bi2);


        bi4 = bi1.multiply(bi2);


        System.out.println( bi3);


        System.out.println( bi4);




}


}

Comments