各类编程语言的Hello World写法

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/whxaing2011/article/details/20736759
(每隔一段时间整理几门语言的HelloWorld写法,更新中......)

A开头:
        1、Android(版本4.2.2)
          Activity:
          package com.javagoboy.helloworld;

          import android.os.Bundle;
          import android.app.Activity;
          import android.view.Menu;

          public class HelloWorld extends Activity {

                    @Override           
                    protected void onCreate(Bundle savedInstanceState) {
                           super.onCreate(savedInstanceState);
                           setContentView(R.layout.activity_hello_world);
                    }
 
                    @Override
                    public boolean onCreateOptionsMenu(Menu menu) {
                           getMenuInflater().inflate(R.menu.hello_world, menu);
                           return true;
                    }
           }
          Activity配置:
          <activity
            android:name="com.javagoboy.helloworld.HelloWorld"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>               
        启动应用:
             
B开头:
C开头:
         
1、C
               vi helloworld.c

               #include<stdio.h>
 
               int main(void) {
                     printf("Hello,World!\n");
                     return 0;
               }
               在Linux环境下执行:
               使用gcc编译:gcc helloworld.c -o helloworld
                            执行:./helloworld

         
2、C++
              vi helloworld.cpp

               #include <stdio.h>
               #include <iostream>

               int main() {

                      puts("Hello,World!");
                      std::cout << "Hello,World!" << std::endl;

                      return 0;
                }
                编译:# g++ helloworld.cpp -o helloworld
                执行:# ./helloworld

D开头:
E开头:
F开头:
G开头:
         1、Go语言
 
               package main
               import (
                     "fmt"
               )
               func main() {
                      fmt.Println("Hello World !");
               }
               保存为:helloworld.go
               执行:go run helloworld.go

H开头:
I开头:
J开头:
        
1、Java

               public class HelloWorld {
                         public static void main(String[] args) {
                                System.out.println("Hello,World !");
                         }
               }
               保存为:HelloWorld.java
               编译:javac HelloWorld.java
               执行:java HelloWorld

            2、JavaScript(ECMAScript派生语言 )

               <html>
                    <title>Hello World</title>
                <body>
                    <script type="text/javascript">
                         document.write("Hello World !");
                         alert("Hello World !");
                    </script>
                </body>
               </html>

K开头:
L开头:
M开头:
N开头:
O开头:
P开头:
       
  1、Python(版本3.3.2)

               命令行:print("Hello World");

Q开头:
R开头:
S开头:
         
1、sh(Shell脚本)

               新建一个.sh文件: vi helloworld.sh
               在helloworld.sh中输入:
               #!/bin/sh
               a="Hello World !"
               echo $a

               修改helloworld.sh为可执行文件:chmod +x helloworld.sh
               执行 ./helloworld.sh
T开头:
U开头:
V开头:
W开头:
X开头:
Y开头:
Z开头

猜你喜欢

转载自blog.csdn.net/whxaing2011/article/details/20736759
今日推荐