📜  30 种不同语言的“Hello World”(1)

📅  最后修改于: 2023-12-03 14:38:51.902000             🧑  作者: Mango

30 种不同语言的 "Hello World"

在计算机科学中,“Hello World”通常是编程最基本的示例程序之一,它用于演示编程语言的基础语法和结构。以下是 30 种不同语言的 "Hello World" 程序示例。

1. C
#include <stdio.h>

int main() {
   printf("Hello, world!");
   return 0;
}
2. C++
#include <iostream>

int main() {
  std::cout << "Hello, world!";
  return 0;
}
3. Java
public class HelloWorld {
  public static void main(String[] args) {
    System.out.println("Hello, world!");
  }
}
4. Python
print("Hello, world!")
5. JavaScript
console.log("Hello, world!");
6. TypeScript
console.log("Hello, world!");
7. Ruby
puts "Hello, world!"
8. PHP
<?php
echo "Hello, world!";
?>
9. Swift
print("Hello, world!")
10. Rust
fn main() {
    println!("Hello, world!");
}
11. Kotlin
fun main() {
    println("Hello, world!")
}
12. Go
package main

import "fmt"

func main() {
    fmt.Println("Hello, world!")
}
13. Scala
object HelloWorld {
  def main(args: Array[String]): Unit = {
    println("Hello, world!")
  }
}
14. Lua
print("Hello, world!")
15. R
print("Hello, world!")
16. Julia
println("Hello, world!")
17. Perl
print "Hello, world!\n";
18. Bash
#!/bin/bash
echo "Hello, world!"
19. PowerShell
Write-Host "Hello, world!"
20. SQL
SELECT 'Hello, world!'
21. Assembly
global _start

section .text
_start:
  mov    edx,len
  mov    ecx,msg
  mov    ebx,1
  mov    eax,4
  int    0x80
  mov    eax,1
  xor    ebx,ebx
  int    0x80

section .data
msg db 'Hello, world!',0xa
len equ $ - msg
22. Dart
void main() {
  print("Hello, world!");
}
23. Elixir
IO.puts "Hello, world!"
24. Lisp
(write-line "Hello, world!")
25. OCaml
print_endline "Hello, world!"
26. Ada
with Ada.Text_IO; use Ada.Text_IO;
procedure Hello is
begin
  Put_Line("Hello, world!");
end Hello;
27. Groovy
println("Hello, world!")
28. Crystal
puts "Hello, world!"
29. Haxe
class Main {
  static function main() {
    trace("Hello, world!");
  }
}
30. Dart Sass
@import 'sass:meta';

@function hello($name: "world") {
  @return "Hello, #{$name}!";
}

body:before {
  content: hello();
}

上述示例展示了许多不同的编程语言,每种语言都有其特定的语法和结构。这个列表只是编程世界中的点缀,其中还有许多其他语言值得探索。Happy coding!