作为一名程序员,在初步学习编程想必都绕不开一个最为基础的入门级示例“Hello World”,那么,你真的了解各个语言“Hello World”的正确写法吗?
1. Java**
class HelloWorld
{
public static void main(String[] args)
{
System.out.println("Hello World!!");
}
}
- C
#include<stdio.h>
int main(void)
{
printf("Hello, world!");
return 0;
}
- Python
print('Hello World')
- C++
#include <iostream>
using namespace std;
int main()
{
cout <<"\nHello World"<< endl;
return 0;
}
- C#
using System;
namespace helloWorld
{
class HelloWorld
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
}
}
}
- Visual Basic .NET
Module HelloWorld
Sub Main( )
System.Console.WriteLine("Hello world!")
End Sub
End Module
- JavaScript
console.log("Hello World");
- PHP
<?php
// In PHP, we use echo to print text
echo "Hello World";
// If you want to print in browser's console, we use print_r
print_r("Hello World");
// if you want the variable data types as well use var_dump
$stringVar = 'hello world';
var_dump($stringVar);
?>
- Objective-C
#import <Foundation/Foundation.h>
int main(int argc, const char * argv[]) {
@autoreleasepool {
NSLog(@"Hello World!");
}
return 0;
}
- SQL
``SELECT 'Hello World';
PRINT 'Hello World';
- Ruby
puts 'Hello World'
- MATLAB
fprintf ( 1, 'Hello, world!' );
quit
上述示例代码均摘自以下代码库(https://github.com/blackbird71SR/Hello-World),你可以从中获取更多示例。
此外,这个代码库是开源的,如果你想添加其中未包含的其他编程语言,欢迎你贡献代码。
原文:
https://towardsdatascience.com/how-to-print-hello-world-in-top-12-most-popular-programming-languages-736d49c6c61c
网友评论