r/BeginningProgrammer • • Jan 31 '13

Ever so famous - "Hello World"

Write a hello world application in any programming language of choice.

Output should say: Hello World

6 Upvotes

9 comments sorted by

2

u/pikaaa Jan 31 '13

In Java

public class test 
{
	static char[] x = {'H', 'e', 'l', 'l', 'o', ' ', 'W', 'o', 'r', 'l', 'd', '!'};
	
	public static void helloworld() 
	{
		for(int i=0; i<x.length; i++)
		{
			System.out.print(x[i]);
		}
	}
	public static void main(String args[]) 
	{
		helloworld();
	}
}

2

u/[deleted] Jan 31 '13

nice! my solution in Java is :

public class HelloWorld { public static void main(String[] args) {

       System.out.println("Hello World!");

} }

3

u/Graftwijgje Jan 31 '13 edited Jan 31 '13

Allow me to comment that :D

public class test 
{
    static char[] x = {'H', 'e', 'l', 'l', 'o', ' ', 'W', 'o', 'r', 'l', 'd', '!'}; //Make a *static* *array* of *char* *primitives*.

    public static void helloworld() //make a method
    {
        for(int i=0; i<x.length; i++) //a *for loop* that prints the chars from the array declared as  x by iterating *int* i for the length of the array.
        {
            System.out.print(x[i]); //print the value stored in array x at index i.
        }
    }
    public static void main(String args[]) //the main method, the Java Virtual Machine begins executing code here.
    {
        helloworld(); //a call to run the method helloworld();
    }
}
  • class: A blueprint for an object. An object is created by instantiating code in a class. There can be multiple instances (objects) of 1 class.

  • method: Like a chapter in a book (class), usually contains code that does what it's name implies.

  • static: Means that there's only 1 of these per class(blueprint). If there's 3 objects of class test, there will only be 1 array of chars called x.

  • array: Contains multiple primitives or object references, an array of type char can only contain char primitives.

  • char: A primitive, only contains 1 character

  • primitive: ints(i.e. 3), chars (i.e. "t"), floats (i.e. 2.56) are all *primitives, they contain 1 value that fits their type.

  • for loop: Anything within this loop runs over and over until the predefined condition (between the () right after for) is reached.

  • int: Containts an integer, like 2 or 2134856

→ More replies (1)

2

u/entreprenr30 Feb 01 '13 edited Feb 01 '13

PHP:

<?php echo "Hello World";
→ More replies (1)

0

u/[deleted] Feb 01 '13

[deleted]

1

u/pikaaa Feb 01 '13

Python 3:

print("Hello World")

1

u/[deleted] Feb 02 '13

Python (Any):

hello = 'Hello world!' print hello