通过本篇文章,我们可以学到python
,javascript
, go
, rust
, java
,c
六种编程语言实现打印输出Hello, world!
的方式。还能学到编译运行的套路,练习编程手感,挺不错的。
python 实现
print("Hello, world!")
# 解释运行 python3 helloworld.py
- 解释运行
python3 helloworld.py
javascript 实现
function main() {
console.log("Hello, world!");
}
main()
// 解释运行 node helloworld.js
- 解释运行
node helloworld.js
rust 实现
fn main() {
println!("Hello, world!");
}
// 编译 rustc helloworld.rs -o helloworld_rs
// 运行 ./helloworld_rs
- 编译
rustc helloworld.rs -o helloworld_rs
- 运行
./helloworld_rs
go 实现
package main
func main() {
println("Hello, World!")
}
// 运行 go run helloworld.go
// 编译 go build helloworld.go
- 解释运行
go run helloworld.go
- 编译构建
go build helloworld.go
- 运行
./helloworld
java 实现
public class helloworld {
public static void main(String[] args) {
System.out.println("Hello World!");
}
}
// 编译 javac helloworld.java
// 运行 java helloworld
- 编译
javac helloworld.java
- 运行
java helloworld
c 实现
#include <stdio.h>
int main(){
puts("Hello, World!");
return 0;
}
// 编译链接 gcc helloworld.c -o helloworld_c
// 运行 ./helloworld_c
- 编译
gcc helloworld.c -o helloworld_c
- 运行
./helloworld_c