向学习编程语言最初的Hello, World!致敬!!!!
JAVA:
- #FileName: HelloWorld.java
- public class HelloWorld #如果有public类的话,类名必须和文件同名,注意大小写
- {
- #Java入口程序,程序从此入口
- public static void main(String[] args)
- {
- #向控制台打印一条语句
- System.out.println(“Hello,World!”);
- }
- }
C:
- #include <stdio.h>
- int main() #main入口函数
- {
- printf(“Hello,World!”); #printf函数打印
- return 1; #函数返回值
- }
C++:
- #include <iostream> //std::cout要用到的头文件
- #include <stdio.h> //标准输入输出头文件
- int main()
- {
- printf(“Hello,World!–Way 1\n”); //printf语句打印
- puts(“Hello,World!–Way 2”); //puts语句
- puts(“Hello,” ” “ “World!–Way 3”); //字符串拼接
- std::cout << “Hello,World!–Way 4” << std::endl; //C++教科书上写法
- return 1; //作为注释
- }
Python:
- >>>> print “Hello,World!” #Python 2.x
- Hello,World!
- >>> print(“Hello,World!”) #Python 3.x
- Hello,World!
C#:
- //FileName: HelloWorld.cs
- using System;
- class TestApp
- {
- public static void Main()
- {
- Console.WriteLine(“Hello,World!”);
- Console.ReadKey();
- }
- }
PHP:
- <!DOCTYPE html>
- <body>
- <?php
- echo “Hello,World!”; //打印语句
- echo “The first php program!”; //打印语句
- echo phpinfo(); //phpinfo()系统函数,输出环境信息
- ?>
- </body>
- </html>
JavaScript:
- var sys = require(“sys”); #导入需要的sys模块
- sys.puts(“Hello,World!”); #调用里面的puts函数来打印字符串
Ruby:
- #可用print语句打印
- print “Hello,World!\n”
- #可用puts语句打印
- puts “Hello,World!\n”
- #可以先声明一个变量,然后再用puts语句
- a = “Hello,World!\n”
- puts a
- #可以先写个函数再调用
- def say(name)
- “Hello,#{name}”
- end
- puts say(“World!”)
R:
- print(“Hello,World!”)
SQL:
- SQL> select ‘Hello,World!’ from dual;
Perl:
- #!C:\Perl\bin #Windows平台下
- #!/usr/bin/env perl #Linux环境下
- print “Hello,World!\n”; #print(“Hello,World”)也可
HTML:
- <!DOCTYPE html>
- <html>
- <body>
- <h1>This is the first program!</h1>
- <p>Hello,World!</p>
- </body>
- </html>
VB:
- ‘FileName: HelloWorld.rb rb作为VB源文件的后缀
- Module Hello
- Sub Main() ‘程序人口函数
- MsgBox(“Hello,World!”) ‘计算机屏幕上显示信息
- End Sub ‘End作为程序块结尾
- End Module ‘单引号作为注释
Scala:
- object HelloWorld
- {
- def main(args:Array[String])
- {
- println(“Hello,World!”);
- }
- }
SHELL:
- #安装了MinGW和MSYS的Windows平台
- D:\HelloWorld>echo “Hello,World!”
- “Hello,World!”
- #Linux平台下
- #echo “Hello,World!” 或 printf “Hello,World!”
- #如果是写在文件中:
- chmod +x HelloWorld.sh
- ./HelloWorld.sh
Delphi:
- procedure TForm1.Button1Click(Sender: TObject);
- begin
- label1.Caption := ‘Hello,World!’;
- end;
- procedure TForm1.FormCreate(Sender: TObject);
- begin
- end;
- end.
Fortran:
- program hello
- print *,”Hello,World!”
- end program hello
TCL:
- <span style=”font-family:SimHei;font-size:14px;”>#命令行交互方式
- D:\>tclsh
- % puts “Hello,World!”
- Hello,World!
- % exit
- D:>
- #文件方式运行
- #!/usr/local/bin/tcl
- puts “Hello, World!”
- D:\>tclsh HelloWorld.tcl
- Hello,World!
FoxPro:
- ?”Hello,World!”
Ada:
- with TEXT_IO;
- procedure HELLO is
- begin
- TEXT_IO.PUT_LINE (“Hello, World!”);
- end HELLO;
AWK:
- [root@Linux ~]# echo | awk ‘{print “Hello,World!”}’
- Hello,World!
- [root@<span style=”font-family: SimHei; font-size: 14px;”>Linux</span><span style=”font-size: 14px; font-family: SimHei;”> ~]# echo | awk ‘BEGIN {print “Hello,World!”}'</span>
- Hello,World!
- [root@Linux ~]# awk ‘BEGIN {print “Hello,World!”}’
- Hello,World!
- [root@Linux ~]# echo “hello world” | awk ‘{print}’
- hello world
Sed:
- # sed -ne ‘1s/.*/Hello, World!/p’
- Hello,World! #第一行为输入
- Hello, world! #
Pascal:
- Program HelloWorld(output);
- begin
- writeln(‘Hello, World!’)
- {程序块的最后一条语句后不需要”;” – 如果添加一个”;”会在程序中增加一个“空语句”}
- end.</span>
Prolog:
- write(“Hello,World!”).