Privacy Policy Cookie Policy Terms and Conditions Hello World - Wikipedia

Hello World

维基百科,自由的百科全书

Hello, World!”程序是一个只在计算机屏幕上打印出“Hello, World!”(英语,意为“世界,你好!”)字串的计算机程序。该程序通常是计算机程序设计语言的初学者所要学习编写的第一个程序。它还可以用来确定该语言的编译器、程序开发环境以及运行环境已经正确安装。

将Hello World程序作为第一个学写的程序,现在已经成为一种传统。该程序最早出现在由Brian Kernighan和Dennis Ritchie写的计算机程序设计教程《C语言程序设计》。

以下是用不同语言写成的Hello World程序的几个例子:

目录

[编辑] 打印到终端

[编辑] Ada

with Ada.Text_Io; use Ada.Text_Io;
procedure Hello is
begin
    Put_Line ("Hello, world!");
end Hello;

[编辑] 汇编语言

[编辑] x86 CPU,DOS,TASM

MODEL SMALL
IDEAL
STACK 100H

DATASEG
    HW      DB      'Hello, world!$'

CODESEG
    MOV AX, @data
    MOV DS, AX
    MOV DX, OFFSET HW
    MOV AH, 09H
    INT 21H
    MOV AX, 4C00H
    INT 21H
END

[编辑] x86 CPU,GNU/Linux,NASM

;"Hello World" for Linux on Intel 80x86 using nasm (Intel syntax).
;Enter this into "hello.asm" then type:
;"nasm -f elf hello.asm"
;"ld hello.o -o hello"
;"./hello"

section .data                   ;data section declaration
msg     db      'Hello World!',0AH
len     equ     $-msg           ;string length

section .text                   ;code section declaration
global  _start                  ;entry point (start of execution)
_start: mov     edx,len         ;string length
        mov     ecx,msg         ;string start
        mov     ebx,1           ;file handle: stdout
        mov     eax,4           ;sys_write
        int     80h             ;kernel system call

        mov     ebx,0           ;return value
        mov     eax,1           ;sys_exit
        int     80h             ;kernel system call

[编辑] x86 CPU,Windows,MASM32

             .386
             .model   flat,stdcall
             option   casemap:none
;Include 文件定义
include   windows.inc
include   user32.inc
includelib user32.lib
include     kernel32.inc
includelib  kernel32.lib
;数据段
            .data
szCaption   db    'A MessageBox!',0
szText      db    'Hello,world!',0
;代码段
            .code
start:
            invoke   MessageBox,NULL,offset szText,offset szCaption,MB_OK
            invoke   ExitProcess,NULL
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
            end  start

[编辑] AWK

BEGIN { print "Hello, world!" }

[编辑] BASIC

传统版BASIC(例如GWBASIC):

10 PRINT "Hello, world!"
20 END

或在提示符輸入:

?"Hello, world!":END

现代版BASIC(例如Quick BASIC):

Print "Hello, world!"

以下的语句在Quick BASIC中同样有效:

? "Hello,world!"

[编辑] BCPL

GET "LIBHDR"

LET START () BE
$(
    WRITES ("Hello, world!*N")
$)

[编辑] Befunge

"!dlrow olleH">v
               ,
              ^_@

[编辑] Brainfuck

++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<
+++++++++++++++.>.+++.------.--------.>+.>.

[编辑] C

 #include <stdio.h>

 int main(void)
 {
     printf("Hello, world!\n");
     return 0;
 }

[编辑] C++

 #include <iostream>

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

[编辑] C++/CLI

int main()
{
    System::Console::WriteLine("Hello, world!");
}

[编辑] C# (C Sharp)

class HelloWorldApp
{
    public static void Main()
    {
        System.Console.WriteLine("Hello, world!");
    }
}

[编辑] COBOL

IDENTIFICATION DIVISION.
PROGRAM-ID.     HELLO-WORLD.

ENVIRONMENT DIVISION.

DATA DIVISION.

PROCEDURE DIVISION.
DISPLAY "Hello, world!".
STOP RUN.

[编辑] Common Lisp

(format t "Hello world!~%")

[编辑] DOS批处理

@echo off
echo "Hello, world!"

[编辑] Eiffel

class HELLO_WORLD

creation
    make
feature
    make is
    local
        io:BASIC_IO
    do
        !!io
        io.put_string("%N Hello, world!")
    end -- make
end -- class HELLO_WORLD

[编辑] Erlang

    -module(hello).
    -export([hello_world/0]).

    hello_world() -> io:fwrite("Hello, World!\n").

[编辑] Forth

." Hello, world!" CR

[编辑] Fortran

    WRITE(*,10)
10  FORMAT('Hello, World!')
    STOP
    END

[编辑] HTML

<HTML>
<HEAD>
<TITLE> Hello World! </TITLE>
</HEAD>
<BODY>
<p>Hello World!</p>
</BODY>
</HTML>

[编辑] HQ9+

H

[编辑] INTERCAL

PLEASE DO ,1 <- #13
DO ,1 SUB #1 <- #238
DO ,1 SUB #2 <- #112
DO ,1 SUB #3 <- #112
DO ,1 SUB #4 <- #0
DO ,1 SUB #5 <- #64
DO ,1 SUB #6 <- #238
DO ,1 SUB #7 <- #26
DO ,1 SUB #8 <- #248
DO ,1 SUB #9 <- #168
DO ,1 SUB #10 <- #24
DO ,1 SUB #11 <- #16
DO ,1 SUB #12 <- #158
DO ,1 SUB #13 <- #52
PLEASE READ OUT ,1
PLEASE GIVE UP

[编辑] Java

public class Hello
{
    public static void main(String[] args)
    {
        System.out.println("Hello, world!");
    }
}

[编辑] JSP

<%
    out.print("Hello, world!");
%>

[编辑] Lua

print "Hello, world!"

[编辑] MIXAL

TERM    EQU    19          the MIX console device number
        ORIG   1000        start address
START   OUT    MSG(TERM)   output data at address MSG
        HLT                halt execution
MSG     ALF    "MIXAL"
        ALF    " HELL"
        ALF    "O WOR"
        ALF    "LD   "
        END    START       end of the program

[编辑] Nuva

<..直接输出..>
Hello, world!

<..或者..>

<.
  // 不带换行
  ?  "Hello, world!"

  // 或者

  // 带换行
  ?? 'Hello, world!'
.>

[编辑] OCaml

let main () =
    print_endline "Hello world!";;

[编辑] Pascal

program Hello;
begin
    writeln('Hello, world!');
end.

[编辑] Perl

#!/usr/local/bin/perl
print "Hello, world!\n";

[编辑] PHP

<?php
    echo 'Hello, world!';//通常使用這個, 比 print 少一個字元
    print 'Hello, world!';
?>

[编辑] Pike

#!/usr/local/bin/pike
int main()
{
    write("Hello, world!\n");
    return 0;
}

[编辑] PL/I

Test: procedure options(main);
    declare My_String char(20) varying initialize('Hello, world!');
    put skip list(My_String);
end Test;

[编辑] Prolog

goal
    write("hello,world!").

[编辑] Python

#!/usr/local/bin/python
print "Hello, world!"

[编辑] REXX

say "Hello, world!"

[编辑] Ruby

#!/usr/bin/ruby
print "Hello, world!\n"

[编辑] Scheme

(display "Hello, world!")
(newline)

[编辑] sed (需要至少一行输入)

sed -ne '1s/.*/Hello, world!/p'

[编辑] Seed7

$ include "seed7_05.s7i";

  const proc: main is func
    begin
      writeln("Hello, world!");
    end func;

[编辑] Smalltalk

Transcript show: 'Hello, world!'

[编辑] SNOBOL

    OUTPUT = "Hello, world!"
END

[编辑] SQL

create table MESSAGE (TEXT char(15));
insert into MESSAGE (TEXT) values ('Hello, world!');
select TEXT from MESSAGE;
drop table MESSAGE;

[编辑] Tcl

#!/usr/local/bin/tcl
puts "Hello, world!"

[编辑] TScript

? "Hello, world!"

[编辑] Turing

put "Hello, world!"

[编辑] UNIX-style shell

程序中的/bin/sh可改为您使用的shell

#!/bin/sh
echo 'Hello, world!'

[编辑] GUI

[编辑] Delphi

program HelloWorld;
uses
    Dialogs;
begin
    ShowMessage('Hello, World!');
end.

[编辑] Nuva

<.
  System.Ui.ShowMessage('Nuva', 'Hello, world!', ['OK'])
.>

[编辑] Visual Basic

MsgBox "Hello, world!"
'或者
Print "Hello, world!"

[编辑] Visual FoxPro

? "Hello, world!"

[编辑] X11

用一个程序

xmessage 'Hello, world!'

用C++和gtkmm 2

#include <iostream>
#include <gtkmm/main.h>
#include <gtkmm/button.h>
#include <gtkmm/window.h>
using namespace std;

class HelloWorld : public Gtk::Window 
{
public:
    HelloWorld();
    virtual ~HelloWorld();
protected:
    Gtk::Button m_button;
    virtual void on_button_clicked();
};

HelloWorld::HelloWorld() : m_button("Hello, world!")
{
    set_border_width(10);
    m_button.signal_clicked().connect(SigC::slot(*this, &HelloWorld::on_button_clicked));
    add(m_button);
    m_button.show();
}

HelloWorld::~HelloWorld() {}

void HelloWorld::on_button_clicked() 
{
    cout << "Hello, world!" << endl;
}

int main (int argc, char *argv[]) 
{
    Gtk::Main kit(argc, argv);
    HelloWorld helloworld;
    Gtk::Main::run(helloworld);
}

[编辑] Java

import java.awt.*;
import java.awt.event.*;

public class HelloFrame extends Frame 
{
    HelloFrame(String title) 
    {
        super(title);
    }
    public void paint(Graphics g)
    {
        super.paint(g);
        java.awt.Insets ins = this.getInsets();
        g.drawString("Hello, World!", ins.left + 25, ins.top + 25);
    }
    public static void main(String args [])
    {
        HelloFrame fr = new HelloFrame("Hello");

        fr.addWindowListener(
            new WindowAdapter() 
            {
                public void windowClosing(WindowEvent e)
                {
                    System.exit( 0 );
                }
            }
        );
        fr.setResizable(true);
        fr.setSize(500, 100);
        fr.setVisible(true);
    }
}

[编辑] Java Applet

Java Applet用于HTML文件。

HTML代码:

<HTML>
<HEAD>
<TITLE>Hello World</TITLE>
</HEAD>
<BODY>

HelloWorld Program says:

<APPLET CODE="HelloWorld.class" WIDTH=600 HEIGHT=100>
</APPLET>

</BODY>
</HTML>

Java代码:

import java.applet.*;
import java.awt.*;

public class HelloWorld extends Applet 
{
    public void paint(Graphics g) 
    {
        g.drawString("Hello, world!", 100, 50);
    }
}

[编辑] JavaScript

JavaScript是一种用于HTML文件的脚本语言。要查看以下程序的运行结果,只要将其复制到任何HTML文本即可。

<script language="javascript">
function helloWorld()
{
    alert("Hello World");
}
</script>

<a href="javascript:this.location()"
onclick="javascript:helloWorld();">Hello World Example</a>

[编辑] PostScript

PostScript是一种专门用来创建图像的语言,常用于打印机。

/font /Courier findfont 24 scalefont
font setfont
100 100 moveto
(Hello World!) show
showpage

[编辑] 外部链接

THIS WEB:

aa - ab - af - ak - als - am - an - ang - ar - arc - as - ast - av - ay - az - ba - bar - bat_smg - be - bg - bh - bi - bm - bn - bo - bpy - br - bs - bug - bxr - ca - cbk_zam - cdo - ce - ceb - ch - cho - chr - chy - closed_zh_tw - co - cr - cs - csb - cu - cv - cy - da - de - diq - dv - dz - ee - el - eml - en - eo - es - et - eu - fa - ff - fi - fiu_vro - fj - fo - fr - frp - fur - fy - ga - gd - gl - glk - gn - got - gu - gv - ha - haw - he - hi - ho - hr - hsb - ht - hu - hy - hz - ia - id - ie - ig - ii - ik - ilo - io - is - it - iu - ja - jbo - jv - ka - kg - ki - kj - kk - kl - km - kn - ko - kr - ks - ksh - ku - kv - kw - ky - la - lad - lb - lbe - lg - li - lij - lmo - ln - lo - lt - lv - map_bms - mg - mh - mi - mk - ml - mn - mo - mr - ms - mt - mus - my - mzn - na - nah - nap - nds - nds_nl - ne - new - ng - nl - nn - no - nov - nrm - nv - ny - oc - om - or - os - pa - pag - pam - pap - pdc - pi - pih - pl - pms - ps - pt - qu - rm - rmy - rn - ro - roa_rup - roa_tara - ru - ru_sib - rw - sa - sc - scn - sco - sd - se - searchcom - sg - sh - si - simple - sk - sl - sm - sn - so - sq - sr - ss - st - su - sv - sw - ta - te - test - tet - tg - th - ti - tk - tl - tlh - tn - to - tokipona - tpi - tr - ts - tt - tum - tw - ty - udm - ug - uk - ur - uz - ve - vec - vi - vls - vo - wa - war - wo - wuu - xal - xh - yi - yo - za - zea - zh - zh_classical - zh_min_nan - zh_yue - zu

Static Wikipedia 2008 (no images)

aa - ab - af - ak - als - am - an - ang - ar - arc - as - ast - av - ay - az - ba - bar - bat_smg - bcl - be - be_x_old - bg - bh - bi - bm - bn - bo - bpy - br - bs - bug - bxr - ca - cbk_zam - cdo - ce - ceb - ch - cho - chr - chy - co - cr - crh - cs - csb - cu - cv - cy - da - de - diq - dsb - dv - dz - ee - el - eml - en - eo - es - et - eu - ext - fa - ff - fi - fiu_vro - fj - fo - fr - frp - fur - fy - ga - gan - gd - gl - glk - gn - got - gu - gv - ha - hak - haw - he - hi - hif - ho - hr - hsb - ht - hu - hy - hz - ia - id - ie - ig - ii - ik - ilo - io - is - it - iu - ja - jbo - jv - ka - kaa - kab - kg - ki - kj - kk - kl - km - kn - ko - kr - ks - ksh - ku - kv - kw - ky - la - lad - lb - lbe - lg - li - lij - lmo - ln - lo - lt - lv - map_bms - mdf - mg - mh - mi - mk - ml - mn - mo - mr - mt - mus - my - myv - mzn - na - nah - nap - nds - nds_nl - ne - new - ng - nl - nn - no - nov - nrm - nv - ny - oc - om - or - os - pa - pag - pam - pap - pdc - pi - pih - pl - pms - ps - pt - qu - quality - rm - rmy - rn - ro - roa_rup - roa_tara - ru - rw - sa - sah - sc - scn - sco - sd - se - sg - sh - si - simple - sk - sl - sm - sn - so - sr - srn - ss - st - stq - su - sv - sw - szl - ta - te - tet - tg - th - ti - tk - tl - tlh - tn - to - tpi - tr - ts - tt - tum - tw - ty - udm - ug - uk - ur - uz - ve - vec - vi - vls - vo - wa - war - wo - wuu - xal - xh - yi - yo - za - zea - zh - zh_classical - zh_min_nan - zh_yue - zu -

Static Wikipedia 2007:

aa - ab - af - ak - als - am - an - ang - ar - arc - as - ast - av - ay - az - ba - bar - bat_smg - be - bg - bh - bi - bm - bn - bo - bpy - br - bs - bug - bxr - ca - cbk_zam - cdo - ce - ceb - ch - cho - chr - chy - closed_zh_tw - co - cr - cs - csb - cu - cv - cy - da - de - diq - dv - dz - ee - el - eml - en - eo - es - et - eu - fa - ff - fi - fiu_vro - fj - fo - fr - frp - fur - fy - ga - gd - gl - glk - gn - got - gu - gv - ha - haw - he - hi - ho - hr - hsb - ht - hu - hy - hz - ia - id - ie - ig - ii - ik - ilo - io - is - it - iu - ja - jbo - jv - ka - kg - ki - kj - kk - kl - km - kn - ko - kr - ks - ksh - ku - kv - kw - ky - la - lad - lb - lbe - lg - li - lij - lmo - ln - lo - lt - lv - map_bms - mg - mh - mi - mk - ml - mn - mo - mr - ms - mt - mus - my - mzn - na - nah - nap - nds - nds_nl - ne - new - ng - nl - nn - no - nov - nrm - nv - ny - oc - om - or - os - pa - pag - pam - pap - pdc - pi - pih - pl - pms - ps - pt - qu - rm - rmy - rn - ro - roa_rup - roa_tara - ru - ru_sib - rw - sa - sc - scn - sco - sd - se - searchcom - sg - sh - si - simple - sk - sl - sm - sn - so - sq - sr - ss - st - su - sv - sw - ta - te - test - tet - tg - th - ti - tk - tl - tlh - tn - to - tokipona - tpi - tr - ts - tt - tum - tw - ty - udm - ug - uk - ur - uz - ve - vec - vi - vls - vo - wa - war - wo - wuu - xal - xh - yi - yo - za - zea - zh - zh_classical - zh_min_nan - zh_yue - zu

Static Wikipedia 2006:

aa - ab - af - ak - als - am - an - ang - ar - arc - as - ast - av - ay - az - ba - bar - bat_smg - be - bg - bh - bi - bm - bn - bo - bpy - br - bs - bug - bxr - ca - cbk_zam - cdo - ce - ceb - ch - cho - chr - chy - closed_zh_tw - co - cr - cs - csb - cu - cv - cy - da - de - diq - dv - dz - ee - el - eml - en - eo - es - et - eu - fa - ff - fi - fiu_vro - fj - fo - fr - frp - fur - fy - ga - gd - gl - glk - gn - got - gu - gv - ha - haw - he - hi - ho - hr - hsb - ht - hu - hy - hz - ia - id - ie - ig - ii - ik - ilo - io - is - it - iu - ja - jbo - jv - ka - kg - ki - kj - kk - kl - km - kn - ko - kr - ks - ksh - ku - kv - kw - ky - la - lad - lb - lbe - lg - li - lij - lmo - ln - lo - lt - lv - map_bms - mg - mh - mi - mk - ml - mn - mo - mr - ms - mt - mus - my - mzn - na - nah - nap - nds - nds_nl - ne - new - ng - nl - nn - no - nov - nrm - nv - ny - oc - om - or - os - pa - pag - pam - pap - pdc - pi - pih - pl - pms - ps - pt - qu - rm - rmy - rn - ro - roa_rup - roa_tara - ru - ru_sib - rw - sa - sc - scn - sco - sd - se - searchcom - sg - sh - si - simple - sk - sl - sm - sn - so - sq - sr - ss - st - su - sv - sw - ta - te - test - tet - tg - th - ti - tk - tl - tlh - tn - to - tokipona - tpi - tr - ts - tt - tum - tw - ty - udm - ug - uk - ur - uz - ve - vec - vi - vls - vo - wa - war - wo - wuu - xal - xh - yi - yo - za - zea - zh - zh_classical - zh_min_nan - zh_yue - zu