【程式教學】各種程式語言的 Hello World!

前言:

  由於「Hello World!」是學任何程式語言的第一步,不管多麼厲害的工程師,再接觸新的程式語言時,各種書籍網站會先教如何印出「Hello World!」因此我突發奇想,想看看各種程式語言中,「Hello World!」是如何顯示的,因此在這裡,我蒐集了各種語言的「Hello World!」的用法。

“Hello World!” 程式碼:

ActionScript

<fx:Script> 
        <![CDATA[ 
            public function initApp():void 
            { 
                mainTxt.text = "Hello World!"; 
            } 
        ]]>
</fx:Script> 

BASH / Shell

echo "Hello World!"

C#

using System;

class Program
{
    static void Main ()
    {
        Console.WriteLine ("Hello World!");
    }
}

C#

using System;

class Program
{
    static void Main ()
    {
        Console.WriteLine ("Hello World!");
    }
}

C語言

#include <stdio.h>

int main ()
{
    printf("Hello World!");

    return 0;
}

C++

#include <iostream>

int main()
{
   std::cout << "Hello World!" << std::endl; 
   
   return 0;
}

Clojure

(ns helloworld.core)

(defn -main [] 
      (println "Hello World!"))

ClodFusion

<cfoutput>#ucase("<h1>hello world!</h1>")#</cfoutput>

Delphi / Pascal

Program HelloWorld (output);
begin
  writeln ('Hello world!');
end.

Erlang

-module (helloworld).
-export ([start/0]).

start() ->
    io:fwrite ("Hello world!\n").

F#

open System

[<EntryPoint>]
let main argv = 
    printfn "Hello World!" 
    0 

Groovy

println ("Hello world!")

Html / XHtml / Xslt

<!DOCTYPE html>
<html>
<head>
    <title>Hello</title>
</head>
<body>
    Hello World!
</body>
</html>

Java / JavaFX

public class HelloWorld
{
     public static void main (String []args)
     {
        System.out.printf ("Hello World!");	// 可格式化,例如 %d
     }
}
public class HelloWorld
{
     public static void main (String []args)
     {
        System.out.print ("Hello World!");	// 不換行
     }
}
public class HelloWorld
{
     public static void main (String []args)
     {
        System.out.println ("Hello World!");	// 自動換行
     }
}

JavaScript

<script>
    alert( 'Hello world!' );
</script>

LaTex

\documentclass[a4paper]{article}
\begin{document}
Hello world!
\end{document}

Lua

print ("Hello World!")

Matlab

fprintf ("Hello World!\n")

Objective – C

#import <Foundation/Foundation.h>

int main (int argc, const char * argv[])
{
   NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

   NSLog (@"Hello World!");
   [pool drain];
   return 0;
}

Perl

print "Hello World!\n";

PHP

<?php
   echo "<h1>Hello World!</h1>\n";
?>

PowerShell

Write-Host 'Hello World!'

Python

print ("Hello World!");

R 語言

print ("Hello World!")

Ruby

puts "Hello World!";

Scala

object HelloWorld 
{
   def main(args: Array[String]) 
   {
      println ("Hello World!")
   }
}

Visual Basic / VB .Net

Module VBModule
    Sub Main()
        Console.WriteLine ("Hello World!")
    End Sub
End Module

Xml

<?xml version="1.0" encoding="UTF-8"?>
<text>
  <para>hello world!</para>
</text>

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。

1 × five =