In this HackerRank Day 0: Hello, World problem solution Complete the code in the editor. The variables i, d, and s are already declared and initialized for you. You must:

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


HackerRank Day 1: Data Types problem solution

Problem solution in Python programming.

# Declare second integer, double, and String variables.

# Read and save an integer, double, and String to your variables.
a = input()
b = input()
c = input()
# Print the sum of both integer variables on a new line.
print(int(a)+i)
# Print the sum of the double variables on a new line.
print(float(b) + d)
# Concatenate and print the String variables on a new line
# The 's' variable above should be printed first.
print(s+c)



Problem solution in Java programming.

        /* Declare second integer, double, and String variables. */
        int iIn = 0;
        double dIn = 0.0;
        String sIn;

        /* Read and save an integer, double, and String to your variables.*/
        iIn = scan.nextInt();
        dIn = scan.nextDouble();
        scan.nextLine();
        sIn = scan.nextLine();

        /* Print the sum of both integer variables on a new line. */
        System.out.println(i + iIn);

        /* Print the sum of the double variables on a new line. */
        System.out.println(d + dIn);
		
        /* Concatenate and print the String variables on a new line; 
        	the 's' variable above should be printed first. */
        System.out.println(s + sIn);




Problem solution in C++ programming.

    
    // Declare second integer, double, and String variables.
    int myInt;
    double myD;
    string myS;
    
    // Read and save an integer, double, and String to your variables.
    cin >> myInt;
    cin >> myD;
    cin.ignore(numeric_limits<streamsize>::max(), '\n');
    getline(cin, myS);

    
    // Print the sum of both integer variables on a new line.
    cout << i+myInt << endl;
    
    // Print the sum of the double variables on a new line.
    printf("%.1lf\n", d+myD);
    // Concatenate and print the String variables on a new line
    // The 's' variable above should be printed first.
    cout << s << myS;
    //printf("%s", myS);
    



Problem solution in C programming.

    // Declare second integer, double, and String variables.
    int i2;
    double d2;
    char s2[50];
    // Read and save an integer, double, and String to your variables.
    scanf("%d\n",&i2);
    scanf("%lf\n",&d2);
    scanf("%[^\n]s",s2);
    // Print the sum of both integer variables on a new line.
    printf("%d\n",i+i2);
    // Print the sum of the double variables on a new line.
    printf("%1.1f\n",d+d2);
    // Concatenate and print the String variables on a new line
    printf("%s%s\n",s,s2);
    // The 's' variable above should be printed first.
    



Problem solution in JavaScript programming.

    // Declare second integer, double, and String variables.
    var myInt = parseInt(input_stdin_array[0]);
    var myDouble = parseFloat(input_stdin_array[1]);
    var myStr = input_stdin_array[2];

    // Read and save an integer, double, and String to your variables.

    // Print the sum of both integer variables on a new line.
    console.log(i + myInt);
    // Print the sum of the double variables on a new line.
    var sum = d + myDouble;
    console.log(sum.toFixed(1));
    // Concatenate and print the String variables on a new line
    // The 's' variable above should be printed first.
    console.log(s.concat(myStr));