Part 1 of 5 in Reading input and writing output  

Hello world by admin

Problem statement

Write Hello world on the console

The output is case sensitive - so make sure you print it exactly as shown in the problem statement

Almost all languages come with 1 or more ways to print output to the console. To solve this problem, you will need to figure out two things:

  1. how to represent a string
  2. how to write to the console in your language

In C, C++, Java and C#, if you know the contents of a string while writing your program, you can simply enclose the contents inside double-quotes to create a string. So to get a string Hello world, we can simply enclose it in quotes like this: "Hello World"

Writing to the console is different in all 4 languages. You can see how it is done for each of the languages below.

printf("Hello world");

In C, we use the printf method. You can find out more about the printf method (including examples) by reading its documentation. Another option is to use the puts method (more info here).

cout << "Hello world";

In C++, we use the insertion operator << on the object cout. cout represents the console output stream in C++. To find out more about how to print different types of data to a stream, you can read the documentation here

System.out.print("Hello world");

Just like C++, Java exposes the console output stream as an object. We can access this object as System.out and use its print method to write out a string. Read more about all the methods of System.out here.

Console.Write("Hello world");

In C#, the static class Console exposes methods that deal with the console. We use the Write method of this class to print a string. Read more about the Console class here.

editorial written by harsha_s

// We include this header to get access to cout

// cout is a part of std namespace
// Without this statement, we will need to refer to it as "std::cout"
// With this statement, we can refer to it as simply "cout"
using namespace std;

int main()
    // Use the << operator on the cout object
    cout << "Hello world";
    // Return 0 to indicate normal termination
    return 0;

featured solution by harsha_s

To try out your code

Sign in

Sign up