Input Format
The first line contains an integer that you must sum with .
The second line contains a double that you must sum with .
The third line contains a string that you must concatenate with .

Output Format
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.
Data types problem solution - 30 days of code HackerRank

Problem solution in the c programming language



int i2;
double d2;
char s2[100]; // this is not scalable for input of unknown size

// Read inputs from stdin
scanf("%d", &i2);
scanf("%lf", &d2);
scanf("%*[\n] %[^\n]", s2); 

// Print outputs to stdout
printf("%d\n", i + i2);
printf("%.01lf\n", d + d2);
printf("%s%s", s, s2);

Problem solution in C++ programming language



// Declare second integer, double, and String variables.
int i2;
double d2;
string s2;

// Read and save an integer, double, and String to your variables.
cin >> i2;
cin >> d2;
getline(cin >> ws, s2); // eat whitespace

// Print the sum of both integer variables on a new line.
cout << i + i2 << endl;

// Print the sum of the double variables on a new line.
cout << fixed << setprecision(1) << d + d2 << endl;

// Concatenate and print the String variables on a new line
// The 's' variable above should be printed first.
cout << s + s2 << endl;

Problem solution in c sharp programming language

// Declare second integer, double, and String variables.
// Read and save an integer, double, and String to your variables.
int i2 = Convert.ToInt32(Console.ReadLine());
double d2 = Convert.ToDouble(Console.ReadLine());
string s2 = Console.ReadLine();

// Print the sum of both integer variables on a new line.
Console.WriteLine(i + i2);

// Print the sum of the double variables on a new line.
Console.WriteLine("{0:.0}", d + d2);

// Concatenate and print the String variables on a new line
// The 's' variable above should be printed first.
Console.WriteLine(s + s2);

Problem solution in Go programming language

var i2 uint32
var d2 float32

fmt.Scanf("%d\n%f\n", &i2, &d2)
s2, _ := scanner.ReadString('\n')

fmt.Println(i + i2)
fmt.Printf("%.1f\n", d + d2)
fmt.Print(s + s2)

Problem solution in Java programming language

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);
        /* Declare second integer, double, and String variables. */
        int i2;
        double d2;
        String s2;
        
        /* Read and save an integer, double, and String to your variables.*/
        i2 = scan.nextInt();
        d2 = scan.nextDouble();
        scan.nextLine(); // read the rest of the line of input (newline character after the double token).
        s2 = scan.nextLine();
       
        /* Print the sum of both integer variables on a new line. */
        System.out.println(i + i2);

        /* Print the sum of the double variables on a new line. */
        System.out.println(d + d2);
      
        /* Concatenate and print the String variables on a new line integer variables on a new line; 
           the 'string` variable above should be printed first. */
        System.out.println(s + s2);
        
        scan.close();
   }
}

Problem solution in JavaScript programming language

// Declare second integer, double, and String variables.
// Read and save an integer, double, and String to your variables.
var i2 = +(readLine());
var d2 = +(readLine());
var s2 = readLine();

// Print the sum of both integer variables on a new line.
console.log(i + i2);

// Print the sum of the double variables on a new line.
console.log((d + d2).toFixed(1));

// Concatenate and print the String variables on a new line
// The 's' variable above should be printed first.
console.log(s + s2);

Problem solution in PHP programming language

$i2 = fgets($handle);
$d2 = fgets($handle);
$s2 = fgets($handle);

printf("%d\n", $i + $i2);
printf("%.1f\n", $d + $d2);
print($s.$s2."\n");

Problem solution in Python programming language



i2 = int(input()) # read int
d2 = float(input()) # read double 
s2 = input() # read string

# print summed and concatenated values
print(i + i2)
print(d + d2)
print(s + s2)

Problem solution in the Swift programming language.

let i2 = Int(readLine()!)
let d2 = Double(readLine()!)
let s2 = readLine()!

// print outputs
print(i + i2!)
print(d + d2!)
print(s + s2)

// --------------------------------
// Alternative approach:
let i2 = readLine()!
let d2 = readLine()!
let s2 = readLine()!

// print outputs
print(i + Int(i2)!)
print(d + Double(d2)!)
print(s + s2)

Problem solution in VB.Net programming language

'Declare second integer, double, and String variables.
'Read and save an integer, double, and String to your variables.
Dim i2 As Integer = Console.ReadLine() 
Dim d2 As Decimal = Console.ReadLine() 
Dim s2 As String = Console.ReadLine()

'Print the sum of both integer variables on a new line.
Console.WriteLine(i + i2)

'Print the sum of the double variables on a new line.
Console.WriteLine(d + d2)

'Concatenate and print the String variables on a new line
'The 's' variable above should be printed first.
Console.WriteLine("{0}{1}", s, s2)

Problem solution in the Scala programming language.

object Solution {
    def main(args: Array[String]) {
        val i = 4
        val d = 4.0
        val s = "HackerRank "
        
        // Read values of another integer, double, and string variables
        // Note use scala.io.StdIn to read from stdin
        val ni = scala.io.StdIn.readInt()
        val nd = scala.io.StdIn.readDouble()
        val ns = scala.io.StdIn.readLine()

        // Print the sum of both the integer variables
        println(i + ni)

        // Print the sum of both the double variables
        println(d + nd)

        // Concatenate and print the string variables
        // The 's' variable above should be printed first.
        println(s + ns)
    }
}