Table of Contents
Day 0: Hello, World
We will solve Day 0: Hello, World Hacker Rank Challenge. In this challenge, you have to use the basic input and output concepts to complete it. You can use basic input-output functions to complete it.
Day 0: Hello, World Hacker Rank Challenge.
Task
You have to read a line of input from stdin to a variable, print Hello, World
on a single line, then, print the value of the variable read from stdin on a second line.
Input Format
An Input String to print on to stdout.
Hello World Hacker Rank Solution in C
Using printf
print the string to stdout.
printf("%s",input_string);
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
int main() {
// Declare a variable named 'input_string' to hold our input.
char input_string[105];
// Read a full line of input from stdin and save it to our variable, input_string.
scanf("%[^\n]", input_string);
// Print a string literal saying "Hello, World." to stdout using printf.
printf("Hello, World.\n");
// TODO: Write a line of code here that prints the contents of input_string to stdout.
printf("%s",input_string);
return 0;
}
Hello World Hacker Rank Solution in C++
Using cout
print the string input.
std::cout<<input_string;
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
// Declare a variable named 'input_string' to hold our input.
string input_string;
// Read a full line of input from stdin (cin) and save it to our variable, input_string.
getline(cin, input_string);
// Print a string literal saying "Hello, World." to stdout using cout.
cout << "Hello, World." << endl;
// TODO: Write a line of code here that prints the contents of input_string to stdout.
std::cout<<input_string;
return 0;
}
Hello World Hacker Rank Solution in Java
Using System.out.println()
method print the input string.
System.out.println(inputString);
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) {
// Create a Scanner object to read input from stdin.
Scanner scan = new Scanner(System.in);
// Read a full line of input from stdin and save it to our variable, inputString.
String inputString = scan.nextLine();
// Close the scanner object, because we've finished reading
// all of the input from stdin needed for this challenge.
scan.close();
// Print a string literal saying "Hello, World." to stdout.
System.out.println("Hello, World.");
System.out.println(inputString);
// TODO: Write a line of code here that prints the contents of inputString to stdout.
}
}