在编程的世界里," Hello World " 往往是开发者开始学习一种新语言时写的第一个程序。这个简单的程序会将 “Hello World“ 输出在我们的屏幕上。看似很简单的行为,实际上对于每一个新学习编程语言的人来说,它代表着新的起点。那么,如何在众多的编程语言中输出” Hello World " 呢?
文章目录- 1. Python
- 2. C
- 3. C
- 4. Java
- 5. C#
- 6. Visual Basic
- 7. JavaScript
- 8. SQL
- 9. Assembly Language
- 10. PHP
- 11. Swift
- 12. Go
- 13. R
- 14. Classic Visual Basic
- 15. MATLAB
- 16. Ruby
- 17. Rust
- 18. Scala
- 19. Perl
- 20. Scratch
- 21. (Visual) FoxPro
- 22. SAS
- 23. Objective-C
我们一起探讨 23 种编程语言,如何在每一种语言中输出 "Hello World " 。无论你是有经验的还是初学者,阅读这篇文章,相信你一定能够有新的了解,你不可能都会吧哈哈哈!!
1. Python
代码语言:javascript复制print('Hello, world!')
2. C
代码语言:javascript复制#include <stdio.h>
int main() {
printf("Hello, World!");
return 0;
}
3. C
代码语言:javascript复制#include <iostream>
int main() {
std::cout << "Hello World!";
return 0;
}
4. Java
代码语言:javascript复制class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}
5. C#
代码语言:javascript复制namespace HelloWorld
{
class Hello {
static void Main(string[] args)
{
System.Console.WriteLine("Hello World!");
}
}
}
6. Visual Basic
代码语言:javascript复制Imports System
Module Module1
Sub Main()
Console.WriteLine("Hello World!")
Console.WriteLine("Press Enter Key to Exit.")
Console.ReadLine()
End Sub
End Module
7. JavaScript
代码语言:javascript复制console.log('Hello World');
8. SQL
代码语言:javascript复制CREATE TABLE helloworld (phrase TEXT);
INSERT INTO helloworld VALUES ("Hello, World!");
SELECT * FROM helloworld;
9. Assembly Language
代码语言:javascript复制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
代码语言:javascript复制<!DOCTYPE html>
<html>
<body>
<h1>My first PHP page</h1>
<?php
echo "Hello World!";
?>
</body>
</html>
11. Swift
代码语言:javascript复制print("Hello, world!")
12. Go
代码语言:javascript复制package main
import "fmt"
func main() {
fmt.Println("hello world")
}
13. R
代码语言:javascript复制Imports System
Module Module1
Sub Main()
Console.WriteLine("Hello World!")
Console.WriteLine("Press Enter Key to Exit.")
Console.ReadLine()
End Sub
End Module
14. Classic Visual Basic
代码语言:javascript复制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
代码语言:javascript复制function y = hello_world
%#codegen
y = 'Hello World!';
16. Ruby
代码语言:javascript复制puts "Hello World"
17. Rust
代码语言:javascript复制fn main() {
println!("Hello World!");
}
18. Scala
代码语言:javascript复制@main def hello() = println("Hello, World!")
19. Perl
代码语言:javascript复制#!/usr/bin/perl
use warnings;
print("Hello, World!n");
20. Scratch
代码语言:javascript复制say Hello World!
21. (Visual) FoxPro
代码语言:javascript复制Messagebox("Hello World!",64)
? "Hello World"
22. SAS
代码语言:javascript复制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
代码语言:javascript复制- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
NSLog (@"Hello, World!");
[pool drain];
return YES;
}
心动不如行动,赶紧试着自己选择几种编程语言,打开编程世界的大门吧~
原文链接:程序员成长家园