Type Here to Get Search Results !

Day 1: HackerRank 30 Days Of Code Solution by CodingHumans | Data Types

0

Day 1: Data Types

Objective

Hey CodingHumans today, we're discussing data types. Data types define and restrict what type values can be stored in a variable, as well as set the rules for what types of operations can be performed on it.

Task

Complete the code in the editor below. The variables i, d, and s are already declared and initialized for you. You must:

Declare 3 variables: one of type int, one of type double, and one of type String.
Read 3 lines of input from stdin (according to the sequence given in the Input Format section below) and initialize your 3 variables.
Use the + operator to perform the following operations:
Print the sum of  i plus your int variable on a new line.
Print the sum of plus your double variable to a scale of one decimal place on a new line.
Concatenate s with the string you read as input and print the result on a new line.

Note: If you are using a language that doesn't support using  for string concatenation (e.g.: C), you can just print one variable immediately following the other on the same line. The string provided in your editor must be printed first, immediately followed by the string you read as input.

Input Style

The first line contains an integer that you must sum with i .
The second line contains a double that you must sum with d.
The third line contains a string that you must concatenate with s.

Output Style

Print the sum of both integers on the first line, the sum of both doubles (scaled to  decimal place) on the second line, and then the two concatenated strings on the third line.

Sample Input

12
4.0
is the best place to learn and practice coding!

Sample Output

16
8.0
HackerRank is the best place to learn and practice coding!

Explanation

When we sum the integers 4 and 12, we get the integer 16 .
When we sum the floating-point numbers 4.0  and 4.0 , we get 8.0 .
When we concatenate HackerRank with is the best place to learn and practice coding!, we get HackerRank is the best place to learn and practice coding!.

You will not pass this challenge if you attempt to assign the Sample Case values to your variables instead of following the instructions above and reading input from stdin.




Recommended: Please try your approach on your integrated development environment (IDE) first, before moving on to the solution.

Few words from CodingHumans : Don't Just copy paste the solution, try to analyze the problem and solve it without looking by taking the the solution as a hint or a reference . Your understanding of the solution matters.


HAPPY CODING 😁





Solution
( Java )

import java.io.*;
import java.util.*;

public class Solution {

    public static void main(String[] args) {
        int i = 4;
        double d = 4.0;
        String s = "HackerRank ";

        Scanner scan = new Scanner(System.in);
        int j=scan.nextInt();
        double k=scan.nextDouble();
        scan.nextLine();
        String l=scan.nextLine();
        System.out.println(i+j);
        System.out.println(d+k);
        System.out.println(s+l);

        /* Declare second integer, double, and String variables. */

        /* Read and save an integer, double, and String to your variables.*/
        // Note: If you have trouble reading the entire String, please go back and review the Tutorial closely.

        /* Print the sum of both integer variables on a new line. */

        /* Print the sum of the double variables on a new line. */

        /* Concatenate and print the String variables on a new line; 
        the 's' variable above should be printed first. */

        scan.close();
    }
}


If you have any doubts regarding this problem or  need the solution in other programming languages then leave a comment down below . 

Post a Comment

0 Comments

Top Post Ad

Below Post Ad