C語言版
#include<stdlib.h>
int main()
{
system("echo HelloWorld");
return 0;
}
c++版
#include<iostream>
using namespace std;
int main()
{
cout<<"HelloWorld";
return 0;
}
java版
package initial;
public class HelloWorld {
public static void main(String[] args) {
System.out.println("HelloWorld");
}
}
python版
print 'HelloWorld'
//你沒看錯,就是這么短一句
html版
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
HelloWorld
</body>
</html>
//你要是願意的話還可以加點樣式
pascal版
program hello;
Begin
writeln("HelloWorld");
readln;
End.
Ruby版
puts "HelloWorld"
//和python一樣只有一句話
javascript版//別看他叫javascript,他和java沒半毛錢關系,想想雷峰塔和雷鋒
console.log("HelloWorld");
PHP版
<?
echo"HelloWorld";
?>
c#版
using system;
namespace HelloWorld
{
class programe
{
static void main(String[] args)
{
Console.WriteLine("HelloWorld");
Console.ReadKey();
}
}
}
//有沒有感覺很像java
Go語言
package main
import "fmt"
func main()
{
fmt.printf("HelloWorld")
}
以上就是各大熱門語言的最簡單程序,一個helloworld並不能學會一個語言,但是還是可以看出一個語言的一些結構的,有的語言以main函數作為入口,有的語言卻沒有,有的語言句尾有分號,有的語言沒有,各個語言都有各自的優勢。
在我看來,一個合格的程序員不一定能精通許多語言,但是他一定能夠讀懂許多語言,所以,希望這篇文章能夠幫助你對各種語言的結構有個大概的認識。