其他
如何用 23 种编程语言说“Hello World”
【CSDN编者按】阅读这篇文章,你将学会用 23 种编程语言说“Hello World”。
原文链接:How To Say “Hello World” In 23 Programming Languages - aster.cloud
未经授权,禁止转载!
在编程的世界里," Hello World " 往往是开发者开始学习一种新语言时写的第一个程序。这个简单的程序会将 "Hello World“ 输出在我们的屏幕上。看似很简单的行为,实际上对于每一个新学习编程语言的人来说,它代表着新的起点。那么,我们如何在众多的编程语言中输出" Hello World " 呢?
在这篇文章中,我们将一起探讨 23 种编程语言,并且告诉你如何在每一种语言中输出 "Hello World " 。无论你是有经验的还是初学者,阅读这篇文章,你会对现在流行的一些编程语言有一个新的了解。
01. Python
print('Hello, world!')
02. C
#include <stdio.h>
int main() {
printf("Hello, World!");
return 0;
}
03. C++
#include <iostream>
int main() {
std::cout << "Hello World!";
return 0;
}
04. Java
class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}
05. C#
namespace HelloWorld
{
class Hello {
static void Main(string[] args)
{
System.Console.WriteLine("Hello World!");
}
}
}
06. Visual Basic
Imports System
Module Module1
Sub Main()
Console.WriteLine("Hello World!")
Console.WriteLine("Press Enter Key to Exit.")
Console.ReadLine()
End Sub
End Module
07. JavaScript
console.log('Hello World');
08. SQL
CREATE TABLE helloworld (phrase TEXT);
INSERT INTO helloworld VALUES ("Hello, World!");
SELECT * FROM helloworld;
09. Assembly Language
global _start
section .text
_start: mov rax, 1 ; system call for write
mov rdi, 1 ; file handle 1 is stdout
mov rsi, message ; address of string to output
mov rdx, 13 ; number of bytes
syscall ; invoke operating system to do the write
mov rax, 60 ; system call for exit
xor rdi, rdi ; exit code 0
syscall ; invoke operating system to exit
section .data
message: db "Hello, World", 10 ; note the newline at the end
10. PHP
<!DOCTYPE html>
<html>
<body>
<h1>My first PHP page</h1>
<?php
echo "Hello World!";
?>
</body>
</html>
11. Swift
print("Hello, world!")
12. Go
package main
import "fmt"
func main() {
fmt.Println("hello world")
}
13. R
print("Hello World!")
14. Classic Visual Basic
Imports System
Module Module1
Sub Main()
Console.WriteLine("Hello World!")
Console.WriteLine("Press Enter Key to Exit.")
Console.ReadLine()
End Sub
End Module
15. MATLAB
function y = hello_world
%#codegen
y = 'Hello World!';
puts "Hello World"
17. Rust
fn main() {
println!("Hello World!");
}
18. Scala
@main def hello() = println("Hello, World!")
19. Perl
#!/usr/bin/perl
use warnings;
print("Hello, World!\n");
20. Scratch
say Hello World!
21. (Visual) FoxPro
Messagebox("Hello World!",64)
? "Hello World"
22. SAS
proc ds2 libs=work;
data _null_;
/* init() - system method */
method init();
declare varchar(16) message; /* method (local) scope */
message = 'Hello World!';
put message;
end;
enddata;
run;
quit;
23. Objective-C
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
NSLog (@"Hello, World!");
[pool drain];
return YES;
}
看完文章,你是否也跃跃欲试了?心动不如行动,赶紧试着自己选择几种编程语言,打开编程世界的大门吧~