Hello World程序样例
Source: Hello World程序样例
Hello World程序样例
以下是用不同语言写成的 HelloWorld 程序的列表:
打印到终端
ActionScript
1 |
|
Ada
1 |
|
汇编语言
x86 CPU,GNU/Linux,NASM
1 |
|
x86 AT&T、Gas
1 |
|
x86 CPU、Windows、MASM32
1 |
|
8086操作系统(NASM)
1 |
|
AutoIt
1 |
|
AWK
1 |
|
Bash (或类似shell)
1 |
|
或者:
1 |
|
BASIC
传统版 BASIC(例如 GWBASIC):
1 |
|
或:
1 |
|
或在提示符輸入:
1 |
|
现代版 BASIC(例如 Quick BASIC):
1 |
|
以下的语句,在 Quick BASIC 中同样有效:
1 |
|
BCPL
1 |
|
Brainfuck
1 |
|
BlitzBasic
1 |
|
BOO
1 |
|
C
1 |
|
或者:
1 |
|
CoffeeScript
1 |
|
或者:
1 |
|
C++
1 |
|
或者:
1 |
|
C++/CLI
1 |
|
C# (C Sharp)
1 |
|
或者(仅用于Microsoft Windows)
1 |
|
或者(使用附加的Windows Forms)
1 |
|
COBOL
1 |
|
Common Lisp
1 |
|
DOS批处理
1 |
|
对于MS-DOS 3.0或更低版本:
1 |
|
Linux Shell
1 |
|
Eiffel
1 |
|
Erlang
1 |
|
Flowgorithm
Forth
1 |
|
Fortran
1 |
|
Go
1 |
|
HQ9+
1 |
|
INTERCAL
1 |
|
Java
1 |
|
JavaScript
该代码适用于浏览器控制台以及Node.js等服务器端运行环境。
1 |
|
Julia
1 |
|
Lisp
1 |
|
Lua
1 |
|
Malbolge
(=<`#9]~6ZY327Uv4-QsqpMn&+Ij"'E%e{Ab~w=_:]Kw%o44Uqp0/Q?xNvL:`H%c#DD2^WV>gY;dts76qKJImZkj
Matlab
1 |
|
Mathematica
Hello[] := Print["``Hello World!``"]
Hello[]
Metapost
1 |
|
MIXAL
1 |
|
Nuva
1 |
|
Objective-C
1 |
|
OCaml
1 |
|
Pascal
1 |
|
Perl
1 |
|
Perl 5.10(含)以後版本:
1 |
|
Pike
1 |
|
PL/I
1 |
|
Prolog
1 |
|
Python
Python 2:
1 |
|
Python 2.6, 2.7, 3:
1 |
|
用"彩蛋""输出Hello World:
1 |
|
REXX
1 |
|
Ruby
1 |
|
Rust
1 |
|
=== Sbyke Laborana ===
1 |
|
Scheme
1 |
|
Scratch
sed
(需要至少一行输入)
1 |
|
Seed7
1 |
|
Smalltalk
1 |
|
Small Basic
TextWindow.WriteLine("Hello, world!")
SNOBOL
1 |
|
SQL
第一种
1 |
|
第二种
1 |
|
第三种
1 |
|
Swift
Swift 1.x:
println("Hello, World!")
Swift 2.x, 3:
print("Hello, World!")
Tcl
1 |
|
TScript
1 |
|
Turing
1 |
|
UNIX-style shell
程序中的/bin/sh可改为您使用的shell
1 |
|
bc
#!/usr/bin/bc -q
print "Hello World"
quit
dc
#!/usr/bin/env dc
[Hello World]p
图形用户界面
AppleScript
1 |
|
或者:
1 |
|
Delphi
1 |
|
Nuva
1 |
|
Visual Basic
1 |
|
Visual FoxPro
1 |
|
X11
用一个程序
1 |
|
使用Qt
1 |
|
C 和 GTK+
1 |
|
用C++和gtkmm 2
1 |
|
Java
1 |
|
Java Applet
Java Applet用于HTML文件。
HTML代码:
1 |
|
Java代码:
1 |
|
JavaScript
JavaScript是一种脚本语言。最广泛用于HTML文件中,也可以用在其它宿主环境下,比如Microsoft® Windows® 脚本宿主(WSH)和一些web服务环境。
用于HTML中:
1 |
|
用于WSH中:
1 |
|
作为服务器端(Node.js):启动后,需要在浏览器中访问"<http://127.0.0.1:8000/>"查看。
1 |
|
PostScript
PostScript是一种专门用来创建图像的语言,常用于打印机。
1 |
|
SPARQL
1 |
|
XAML
1 |
|
接著使用 C# 建置
1 |
|
易语言
1 |
|
服务器端
以下为Web服务端示例程序,程序启动后,需要用浏览器访问特定地址来查看结果。
ASP
1 |
|
或者简单地写成:
1 |
|
HTML
1 |
|
Go
1 |
|
JSP
1 |
|
或者简单地写成:
1 |
|
JavaScript
以下为Node.js环境:
1 |
|
PHP
以下代码既可以作为服务器端运行,显示在用户浏览器上,也可以在终端中直接运行,输出到终端中:
1 |
|
或者
1 |
|