Hello World 2 – Computer Sir Ki Class

Login


Lost your password?

Don't have an account ?
Register (It's FREE) ×
  

Login
[lwa]



Code Learning #JAVA#551 siteicon   siteicon   siteicon  

Hello World 2

This is a program that prints hello world! given as two separate words.

Learning Objectives

To learn java concepts related to :

  • adding two parts of a string while printing.

Program Approach

The objective is just to demonstrate the use of + for displaying two strings Since we want the two words hello and world to be displayed adjacently we will use two separate string literals concatenated (added) with +sign.

Source Code

TC++ #551

Source Code

Run Output

Hello World!

Code Understanding

System.out.println(“Hello “+”World!”);

In this statement we have put the two words to be displayed as two separate string literals within” ” (double quotes). We will then join these string literals using a + operator in between. The compiler would automatically assume + as a string joiner and not as arithmetic + , what it is usually meant for.


Suggested Filename(s): HelloWorld2.java



Share

admin| Created: 16-Aug-2016 | Updated: 13-Dec-2017|






Back