我们刚开始接触计算机语言大多从Hello world 开始,下面演示各种语言的Hello world program:
AKA 控制台
WHILE (1=1) :
WRITE "Hello World "
with Ada.Text_Io; use Ada.Text_Io;
procedure Hello is
begin
Put_Line ("Hello, world!");
end Hello;
PROC main()
WriteF('Hello, World!')
ENDPROC
'Hello World'
Accumulator-only architecture: DEC PDP-8, PAL-III assembler
See the Example section of the PDP-8 article.
-
Accumulator + index register machine: MOS 6502, CBM, ca65 asm
MSG: .ASCIIZ "Hello, world!"
LDX #0
LDA MSG,X ; load initial char
@LP: JSR $FFD2 ; CHROUT CBM KERNAL
INX
LDA MSG,X
BNE @LP
RTS
Accumulator/Index microcoded machine: Data General Nova, RDOS
See the example section of the Nova article.
Expanded accumulator machine: Intel x86, MS-DOS, TASM
MODEL SMALL
IDEAL
STACK 100H
DATASEG
MSG DB 'Hello, world!$'
CODESEG
MOV AX, @data
MOV DS, AX
MOV DX, OFFSET MSG
MOV AH, 09H ; DOS: output ASCII$ string
INT 21H
MOV AX, 4C00H
INT 21H
END
- General-purpose-register CISC: DEC PDP-11, RT-11, MACRO-11
.MCALL .REGDEF,.TTYOUT,.EXIT
.REGDEF
HELLO: MOV #MSG,R1
MOVB (R1),R0
LOOP: .TTYOUT
MOVB +(R1),R0
BNE LOOP
.EXIT
MSG: .ASCIZ /HELLO, WORLD!/
.END HELLO
CISC: VAX, VMS, MACRO32
.title hello
term_name: .ascid /SYS$INPUT/
term_chan: .blkw 1
out_iosb: .blkq 1
msg: .asciz /Hello, world!/
.entry start,0
; establish a channel for terminal I/O
$assign_s devnam=term_name,-
chan=term_chan
blbc r0,error
; queue the I/O request
$qio_s chan=term_chan,-
func=#io$_writevblk,-
iosb=out_iosb,-
p1=msg,-
p2=#13
blbc r0,error
$exit_s ; normal exit
error: halt ; error condition
.end start
BEGIN { print "Hello, world!" }
-
BASIC
- MS BASIC (traditional, unstructured)
10 PRINT "Hello, world!"
20 END
- TI-BASIC
isp "Hello, world!"
- Structured BASIC
print "Hello, world!"
-
BCPL
GET "LIBHDR"
LET START () BE
$(
WRITES ("Hello, world!*N")
$)
#include <stdio.h></stdio.h>
int main(void) {
printf("Hello, world!\n");
return 0;
}
#include <iostream><br> using namespace std;</iostream>
int main() {
cout << "Hello, world!" << endl;
return 0;
}
class HelloWorldApp {
public static void Main() {
System.Console.WriteLine("Hello, world!");
}
}
module hello
Start :: String
Start = "Hello, world"
PROC 0
WRITE Hello, World!
IDENTIFICATION DIVISION.
PROGRAM-ID. HELLO-WORLD.
ENVIRONMENT DIVISION.
DATA DIVISION.
PROCEDURE DIVISION.
DISPLAY "Hello, world!".
STOP RUN.
(format t "Hello world!~%")
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
-module(hello).
-export([hello_world/0]).
hello_world() -> io:fwrite("Hello, world!\n").
." Hello, world!" CR
PROGRAM HELLO
WRITE(*,10)
10 FORMAT('Hello, world!')
STOP
END
module HelloWorld (main) where
main = putStr "Hello World\n"
ON ENTER {
"Hello, " "World!" & SAY
}
public class Hello {
public static void main(String[] args) {
System.out.println("Hello, world!");
}
}
print [hello world!]
print "Hello, world!"
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
@echo off
echo Hello, world!
-
OCaml
let _ =
print_endline "Hello world!";;
-
OPL
PROC hello:
PRINT "Hello, World"
ENDP
-
Pascal
program Hello;
begin
writeln('Hello, world!');
end.
- Perl
print "Hello, world!\n";
<?php <br /> 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;
print "Hello, world!"
-
REXX, also NetRexx and Object REXX
say "Hello, world!"
print "Hello, world!\n"
class HELLO_WORLD is
main is
#OUT+"Hello World\n";
end;
end;
(display "Hello, world!")
(newline)
-
sed (requires at least one line of input)
sed -ne '1s/.*/Hello, world!/p'
'Hello, World!' uppercase print.
Transcript show: 'Hello, world!'
print "Hello, world!\n";
OUTPUT = "Hello, world!"
END
create table MESSAGE (TEXT char(15));
insert into MESSAGE (TEXT) values ('Hello, world!');
select TEXT from MESSAGE;
drop table MESSAGE;
Or, more simply
print 'Hello, World.'
sub main
print "Hello, World"
end sub
puts "Hello, world!"
put "Hello, world!"
echo 'Hello, world!'
-
Romanian pseudocode (UBB Cluj-Napoca)
Algoritmul Salut este:
fie s:="Hello, world";
tipareste s;
sf-Salut
-
传统图形界面应用开发工具
-
C++ bindings for GTK graphics toolkit
#include <iostream><br> #include <gtkmm main=""><br> #include <gtkmm button=""><br> #include <gtkmm window=""><br> using namespace std;</gtkmm></gtkmm></gtkmm></iostream>
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:
lot(*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);
return 0;
}
import java.awt.*;
import java.awt.event.*;
public class HelloFrame extends Frame {
HelloFrame(String title) {
super(title);
}
public void paint(Graphics g) {
super.paint
;
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);
}
}
#include <qapplication.h><br> #include <qpushbutton.h><br> #include <qwidget.h><br> #include <iostream></iostream></qwidget.h></qpushbutton.h></qapplication.h>
class HelloWorld : public QWidget
{
Q_OBJECT
public:
HelloWorld();
virtual ~HelloWorld();
public slots:
void handleButtonClicked();
QPushButton *mPushButton;
};
HelloWorld::HelloWorld() :
QWidget(),
mPushButton(new QPushButton("Hello, World!", this))
{
connect(mPushButton, SIGNAL(clicked()), this, SLOT(handleButtonClicked()));
}
HelloWorld::~HelloWorld() {}
void HelloWorld::handleButtonClicked()
{
std::cout << "Hello, World!" << std::endl;
}
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
HelloWorld helloWorld;
app.setMainWidget(&helloWorld);
helloWorld.show();
return app.exec();
}
MsgBox "Hello, world!"
#include <windows.h></windows.h>
LRESULT CALLBACK WindowProcedure(HWND, UINT, WPARAM, LPARAM);
char szClassName[] = "MainWnd";
HINSTANCE hInstance;
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
HWND hwnd;
MSG msg;
WNDCLASSEX wincl;
hInstance = hInst;
wincl.cbSize = sizeof(WNDCLASSEX);
wincl.cbClsExtra = 0;
wincl.cbWndExtra = 0;
wincl.style = 0;
wincl.hInstance = hInstance;
wincl.lpszClassName = szClassName;
wincl.lpszMenuName = NULL; //No menu
wincl.lpfnWndProc = WindowProcedure;
wincl.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1); //Color of the window
wincl.hIcon = LoadIcon(NULL, IDI_APPLICATION); //EXE icon
wincl.hIconSm = LoadIcon(NULL, IDI_APPLICATION); //Small program icon
wincl.hCursor = LoadCursor(NULL, IDC_ARROW); //Cursor
if (!RegisterClassEx(&wincl))
return 0;
hwnd = CreateWindowEx(0, //No extended window styles
szClassName, //Class name
"", //Window caption
WS_OVERLAPPEDWINDOW & ~WS_MAXIMIZEBOX,
CW_USEDEFAULT, CW_USEDEFAULT, //Let Windows decide the left and top positions of the window
120, 50, //Width and height of the window,
NULL, NULL, hInstance, NULL);
//Make the window visible on the screen
ShowWindow(hwnd, nCmdShow);
//Run the message loop
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
LRESULT CALLBACK WindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
PAINTSTRUCT ps;
HDC hdc;
switch (message)
{
case WM_PAINT:
hdc = BeginPaint(hwnd, &ps);
TextOut(hdc, 15, 3, "Hello, world!", 13);
EndPaint(hwnd, &ps);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, message, wParam, lParam);
}
return 0;
}
基于web图形用户界面
Java applets work in conjunction with HTML files.
HelloWorld Program says:
<applet height="100" width="600" code="HelloWorld"> <br>??? </applet>
import java.applet.*;
import java.awt.*;
public class HelloWorld extends Applet {
public void paint(Graphics g) {
g.drawString("Hello, world!", 100, 50);
}
}
-
JavaScript, aka ECMAScript
JavaScript is a scripting language used in HTML files. To demo this program Cut and Paste the following code into any HTML file.
???? function helloWorld()
???? {
???????? javascript: alert("Hello, world!");
???? }
????
onclick="javascript:helloWorld();">Hello World Example
An easier method uses JavaScript implicitly, calling the reserved alert function. Cut and paste the following line inside the .... HTML tags.
Hello World Example
An even easier method involves using popular browsers' support for the virtual 'javascript' protocol to execute JavaScript code. Enter the following as an Internet address (usually by pasting into the address box):
javascript:alert('Hello, world!')
<window there="" gatekeeper="" keymaster="" www="" http="" xmlns="<A href=">http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"><br><box align="center"><br><label value="Hello, world!"><br></label></box><br></window>
-
文档格式
-
-
ASCII
The following sequence of characters, expressed in hexadecimal notation (with carriage return and newline characters at end of sequence):
48 65 6C 6C 6F 2C 20 77 6F 72 6C 64 21 0D 0A
Hello, world!
/font /Courier findfont 24 scalefont
font setfont
100 100 moveto
(Hello world!) show
showpage
\font\HW=cmr10 scaled 3000
\leftline{\HW Hello world}
\bye
分享到:
相关推荐
#Learning Ionic Framework A Hello World Application 你了解多少种计算机语言?...专为程序猿量身打造,全面的语言百科,趣味的问答小游戏,茶余饭后,夜深人静,请来一打 Hello World ,不用客气!
“别再更新了,实在是学不动了”这句话道出了多少前端开发者的心声,”不幸”的是 Vue 的作者在国庆区间发布了 Vue3.0 的 pre-Aplha 版本,这意味着 Vue3.0 快要和我们见面了。既来之则安之,扶我起来我要开始讲了。...
这是一本非常有趣的编程启蒙书,...编程将会改变我们的思维,教会我们如何思考,让我们的思维插上计算机的翅膀,以一种全新的方式来看世界。现在就让我们一起走进计算机编程的神奇世界,探索和发现计算机编程的魔力吧。
这是一本非常有趣的编程启蒙书,...编程将会改变我们的思维,教会我们如何思考,让我们的思维插上计算机的翅膀,以一种全新的方式来看世界。现在就让我们一起走进计算机编程的神奇世界,探索和发现计算机编程的魔力吧!
这是一本非常有趣的编程启蒙书,...编程将会改变我们的思维,教会我们如何思考,让我们的思维插上计算机的翅膀,以一种全新的方式来看世界。现在就让我们一起走进计算机编程的神奇世界,探索和发现计算机编程的魔力吧
这是一本非常有趣的编程启蒙书,...编程将会改变我们的思维,教会我们如何思考,让我们的思维插上计算机的翅膀,以一种全新的方式来看世界。现在就让我们一起走进计算机编程的神奇世界,探索和发现计算机编程的魔力吧。
leetcode 答案 每日一题(也称大佬带我装逼带我飞) 1. 这家前后端关系肯定好不到哪里去 出题人 B大 这段php代码 可能输出一个 JSON 也可能输出空 const foo = { bar: <?php> ...Chobits:这样写代
现在混在职场,如果不懂一点人工智能...2、让你在茶余饭后闲谈时,参加大咖的AI交流沙龙时,面试Ai公司准备资料时,更熟悉和从容。 3、我希望用小白最能懂的话解释一些我们不懂的知识,因为我和你都是AI领域的修行者。
源码可能使用了CSS3媒体查询、Bootstrap框架或其他方法来实现这一目标。 8. **错误处理与日志记录** 优秀的源码会包含良好的错误处理机制,通过try-catch结构捕获异常,并记录到日志,便于调试和排查问题。 9. **...
QQ游戏“大家来找茬”自推出以来便吸引了大量玩家的眼球,成为了人们茶余饭后缓解压力的优选。这款游戏中,玩家将面临一项挑战:在两张极为相似的图片中,找出那些微小的差别。这项活动看似简单,实际上却能够充分...
这是半年来,在看ULA的过程中,针对Linux 2.6.24内核顺手做的一点注释。内容不多,个人觉得文件系统和USB这两个模块的注释还有一点意思。 所有注释都是中文,您可以与标准2.6.24内核进行比较,看看具体的注释内容。 ...
每当我们想到Linux是我们就想到了这本书,每当烦恼分布式系统的实现时,我们就想到了这本书,每当茶余饭后无所事事时,我们就想起了这本书。你,我的朋友!看看吧
随着社会的进步,影片成了人们茶余饭后的重要部分,那么为了更好的管理好影片,经营商对影碟租借管理系统的要求,对客户管理的困难。如果要设计一套针对经营影碟租借系统就特别有用,特别有深刻的意义,并且是现代的...
随着社会的进步,影片成了人们茶余饭后的重要部分,那么为了更好的管理好影片,经营商对影碟租借管理系统的要求,对客户管理的困难。如果要设计一套针对经营影碟租借系统就特别有用,特别有深刻的意义,并且是现代的...
疯人院 v1.0.4 当前版本:1.0.4 软件语言:中文 ...我们会每天更新最优质的内容,以便您可以在茶余饭后等人等车上厕所发呆无聊的时候为自己找点乐子。 我们会保持功能的更新和优化,打造出一款优质的疯友软件。
随着社会的进步,影片成了人们茶余饭后的重要部分,那么为了更好的管理好影片,经营商对影碟租借管理系统的要求,对客户管理的困难。如果要设计一套针对经营影碟租借系统就特别有用,特别有深刻的意义,并且是现代的...
让我们先回顾一下事件发生的背景。2020年的东京夏季奥运会,作为全球瞩目的体育盛事,为各路商家提供了前所未有的宣传机会。然而,这家饮料公司所生产的“苦瓜汁”由于之前发生的产品质量危机,导致其销售量大幅下滑...
《懒羊羊经典语录精选》是一部深受广大观众喜爱的动画作品《喜羊羊与灰太狼》中的角色——懒羊羊的...通过对懒羊羊经典语录的回顾和分享,我们不仅能够重温那些美好的动画时光,还能在忙碌的生活中找到一份纯真和快乐。