本文向我们介绍了如何跨各种语言编写“Hello World”的第一个计算机程序。与程序一起,提供注释以更好地理解程序中使用的术语和关键字
学习任何编程都可以简化为:
- 在文本编辑器编写程序,并用正确的扩展名保存它(Java等)
- 使用编译器或在线 IDE 编译程序
- 了解基本术语。
“Hello World”程序是学习任何编程语言的第一步,也是您将学习的最简单的程序之一。您所要做的就是在屏幕上显示消息“Hello World”。现在让我们看看大多数语言的程序:
以下是所有不同语言的“Hello World”程序的链接:
1. C 语言的 Hello World
C
// Simple C program to
// display "Hello World"
// Header file for
// input output functions
#include
// main function -
// where the execution of
// program begins
int main()
{
// prints hello world
printf("Hello World");
return 0;
}
C++
// Simple C++ program to
// display "Hello World"
// Header file for
// input output functions
#include
using namespace std;
// main function -
// where the execution of
// program begins
int main()
{
// prints hello world
cout << "Hello World";
return 0;
}
C#
// C# program to print Hello World!
using System;
// namespace declaration
namespace HelloWorldApp {
// Class declaration
class Geeks {
// Main Method
static void Main(string[] args)
{
// statement
// printing Hello World!
Console.WriteLine("Hello World");
// To prevents the screen from
// running and closing quickly
Console.ReadKey();
}
}
}
Java
// This is a simple Java program.
// FileName : "HelloWorld.java"
class HelloWorld {
// Your program begins
// with a call to main().
// Prints "Hello, World"
// to the terminal window.
public static void main(
String args[])
{
System.out.println("Hello World");
}
}
Python
# Python code for "Hello World"
print("Hello World")
Perl
#!/usr/bin/perl
# Modules used
use strict;
use warnings;
# Print function
print("Hello World\n");
# To run the code refer:
# http://bit.ly/2qLYVTG
Scala
// Scala program to print Hello World!
object Geeks
{
// Main Method
def main(args: Array[String])
{
// prints Hello World
println("Hello World")
}
}
Go
// Go program to print Hello World!
package main
import "fmt"
// Main function
func
main()
{
// prints Hello World
fmt.Println("!... Hello World ...!")
}
PHP
HTML
Hello World
JavaScript
Julia
// Julia program
println("Hello World")
R
# Code
cat('Hello World')
Ruby
# code
puts "Hello World"
Solidity
pragma solidity ^0.5.0;
contract helloGeeks {
function renderHelloGeeks () public pure returns (string) {
return 'Hello World';
}
}
XML
Hello World
ObjectiveC
#import
#import
int main(void)
{
NSLog(@"Hello World
");
return 0;
}
Kotlin
fun main(args: Array) {
println("Hello World")
}
Dart
void main() {
print('Hello World');
}
C
// Simple C program to
// display "Hello World"
// Header file for
// input output functions
#include
// main function -
// where the execution of
// program begins
int main()
{
// prints hello world
printf("Hello World");
return 0;
}
C++
// Simple C++ program to
// display "Hello World"
// Header file for
// input output functions
#include
using namespace std;
// main function -
// where the execution of
// program begins
int main()
{
// prints hello world
cout << "Hello World";
return 0;
}
C#
// C# program to print Hello World!
using System;
// namespace declaration
namespace HelloWorldApp {
// Class declaration
class Geeks {
// Main Method
static void Main(string[] args)
{
// statement
// printing Hello World!
Console.WriteLine("Hello World");
// To prevents the screen from
// running and closing quickly
Console.ReadKey();
}
}
}
Java
// This is a simple Java program.
// FileName : "HelloWorld.java"
class HelloWorld {
// Your program begins
// with a call to main().
// Prints "Hello, World"
// to the terminal window.
public static void main(
String args[])
{
System.out.println("Hello World");
}
}
Python
# Python code for "Hello World"
print("Hello World")
Perl
#!/usr/bin/perl
# Modules used
use strict;
use warnings;
# Print function
print("Hello World\n");
# To run the code refer:
# http://bit.ly/2qLYVTG
Scala
// Scala program to print Hello World!
object Geeks
{
// Main Method
def main(args: Array[String])
{
// prints Hello World
println("Hello World")
}
}
HTML
Hello World
PHP
Julia
println("Hello World")
Ruby
puts "Hello World"
R
cat('Hello World')
Go
package main
import "fmt"
// Main function
func main() {
fmt.Println("Hello World")
}
Javascript
Solidity
pragma solidity ^0.5.0;
contract helloGeeks {
function renderHelloGeeks () public pure returns (string) {
return 'Hello World';
}
}
XML
Hello World
ObjectiveC
#import
#import
int main(void)
{
NSLog(@"Hello World
");
return 0;
}
Kotlin
fun main(args: Array) {
println("Hello World")
}
Dart
void main() {
print('Hello World');
}
2. C++中的Hello World
C++
// Simple C++ program to
// display "Hello World"
// Header file for
// input output functions
#include
using namespace std;
// main function -
// where the execution of
// program begins
int main()
{
// prints hello world
cout << "Hello World";
return 0;
}
3. C#中的Hello World
C#
// C# program to print Hello World!
using System;
// namespace declaration
namespace HelloWorldApp {
// Class declaration
class Geeks {
// Main Method
static void Main(string[] args)
{
// statement
// printing Hello World!
Console.WriteLine("Hello World");
// To prevents the screen from
// running and closing quickly
Console.ReadKey();
}
}
}
4. Java的Hello World
Java
// This is a simple Java program.
// FileName : "HelloWorld.java"
class HelloWorld {
// Your program begins
// with a call to main().
// Prints "Hello, World"
// to the terminal window.
public static void main(
String args[])
{
System.out.println("Hello World");
}
}
5. Python的Hello World
Python
# Python code for "Hello World"
print("Hello World")
6. Perl 中的 Hello World
珀尔
#!/usr/bin/perl
# Modules used
use strict;
use warnings;
# Print function
print("Hello World\n");
# To run the code refer:
# http://bit.ly/2qLYVTG
7. Scala 中的 Hello World
斯卡拉
// Scala program to print Hello World!
object Geeks
{
// Main Method
def main(args: Array[String])
{
// prints Hello World
println("Hello World")
}
}
8. Go 中的 Hello World
走
// Go program to print Hello World!
package main
import "fmt"
// Main function
func
main()
{
// prints Hello World
fmt.Println("!... Hello World ...!")
}
9. PHP的Hello World
PHP
10. HTML 中的 Hello World
HTML
Hello World
11. JavaScript 中的 Hello World
JavaScript
12. Julia 中的 Hello World
朱莉娅
// Julia program
println("Hello World")
13. R 中的 Hello World
电阻
# Code
cat('Hello World')
14. Ruby 中的 Hello world
红宝石
# code
puts "Hello World"
15. Solidity 中的 Hello World
坚固性
pragma solidity ^0.5.0;
contract helloGeeks {
function renderHelloGeeks () public pure returns (string) {
return 'Hello World';
}
}
16. XML 中的 Hello World
XML
Hello World
17. Objective-C 中的 Hello World
目标C
#import
#import
int main(void)
{
NSLog(@"Hello World
");
return 0;
}
18. Kotlin 中的 Hello World
科特林
fun main(args: Array) {
println("Hello World")
}
19. Dart的Hello World
Dart
void main() {
print('Hello World');
}
以下是所有语言的代码:
C
// Simple C program to
// display "Hello World"
// Header file for
// input output functions
#include
// main function -
// where the execution of
// program begins
int main()
{
// prints hello world
printf("Hello World");
return 0;
}
C++
// Simple C++ program to
// display "Hello World"
// Header file for
// input output functions
#include
using namespace std;
// main function -
// where the execution of
// program begins
int main()
{
// prints hello world
cout << "Hello World";
return 0;
}
C#
// C# program to print Hello World!
using System;
// namespace declaration
namespace HelloWorldApp {
// Class declaration
class Geeks {
// Main Method
static void Main(string[] args)
{
// statement
// printing Hello World!
Console.WriteLine("Hello World");
// To prevents the screen from
// running and closing quickly
Console.ReadKey();
}
}
}
Java
// This is a simple Java program.
// FileName : "HelloWorld.java"
class HelloWorld {
// Your program begins
// with a call to main().
// Prints "Hello, World"
// to the terminal window.
public static void main(
String args[])
{
System.out.println("Hello World");
}
}
Python
# Python code for "Hello World"
print("Hello World")
珀尔
#!/usr/bin/perl
# Modules used
use strict;
use warnings;
# Print function
print("Hello World\n");
# To run the code refer:
# http://bit.ly/2qLYVTG
斯卡拉
// Scala program to print Hello World!
object Geeks
{
// Main Method
def main(args: Array[String])
{
// prints Hello World
println("Hello World")
}
}
HTML
Hello World
PHP
朱莉娅
println("Hello World")
红宝石
puts "Hello World"
电阻
cat('Hello World')
走
package main
import "fmt"
// Main function
func main() {
fmt.Println("Hello World")
}
Javascript
坚固性
pragma solidity ^0.5.0;
contract helloGeeks {
function renderHelloGeeks () public pure returns (string) {
return 'Hello World';
}
}
XML
Hello World
目标C
#import
#import
int main(void)
{
NSLog(@"Hello World
");
return 0;
}
科特林
fun main(args: Array) {
println("Hello World")
}
Dart
void main() {
print('Hello World');
}
输出:
Hello World