プログラミング言語

Hello Worldプログラム

16 コメント
views
0 フォロー

新しくプログラミング言語を学ぶとき、必ずと言っていいほど一番最初に作るのはHello Worldプログラムと言うのが定番となっております。
単に「Hello,World!」と言う文字列を表示するだけの簡単なプログラムです。
n番煎じ感がありますが、ここでは様々な言語のHello Worldプログラムを纏めてみようと思います。

知らない言語は調べながらやるので間違っているところがあるかも知れません。

とくに
作成: 2020/07/02 (木) 21:02:20
最終更新: 2020/07/03 (金) 22:49:34
通報 ...
1
とくに 2020/07/02 (木) 21:06:59

C言語

#include <stdio.h>

int main(){
	printf("Hello,World!\n");
	return 0;
}
2
とくに 2020/07/02 (木) 21:08:34 修正

C++

#include <iostream>

using namespace std;
int main(){
	cout << "Hello,World!" << endl;
	return 0;
}
3
とくに 2020/07/02 (木) 21:16:45 修正

JavaScript

console.log("Hello,world!");

alert版

alert("Hello,World!");

DOM操作版

<html>
 <head>
  <meta charset="utf-8">
  <title>Hello,World!</title>
 </head>
 <body>
  <div></div>
  <script>
	let d = document.getElementByTagName("div")[0];
	d.textContent = "Hello,World!";
  </script>
 </body>
</html>
4
とくに 2020/07/02 (木) 21:20:24

PHP

<html>
 <head>
  <meta charset="utf-8">
  <title><?php echo "Hello,World!"?></title>
 </head>
 <body>
  <div><?php echo "Hello,Wordl!"?></div>
 </body>
</html>
5
とくに 2020/07/02 (木) 21:57:25 修正

C#

using System

class HelloWorld{
	static void Main(string[] args){
		Console.Out.WriteLine("Hello,World!");
	}
}
6
とくに 2020/07/02 (木) 22:04:49

Java

public class HelloWorld{
	public static void Main(String[] args){
		System.out.println("Hello,World!");
	}
}
7
とくに 2020/07/02 (木) 22:11:06 修正

BASIC

10 PRINT "Hello,World!"
20 END
8
とくに 2020/07/02 (木) 22:29:53

Visual Basic

Private Sub Command1_Click()
	MsgBox "Hello, World!"
End Sub
9
とくに 2020/07/02 (木) 22:32:52

Python

print "Hello,Wordl!"

Python 3.0以降

print("Hello,World!")
10
とくに 2020/07/02 (木) 22:41:47

FORTRAN

program main
print *,"Hello,World!"
end program main
11
とくに 2020/07/02 (木) 22:50:44

COBOL

000001 IDENTIFICATION DIVISION.
000002 PROGRAM-ID. hello.
000003 PROCEDURE DIVISION.
000004     DISPLAY "Hello, world!".
000005     STOP RUN.
12
とくに 2020/07/02 (木) 22:59:10

Ruby

puts "Hello,Wrold!"
13
とくに 2020/07/02 (木) 23:05:12

HSP

mes "Hello,World!"
14
とくに 2020/07/02 (木) 23:14:21

Swift

println("Hello,World!")
15
とくに 2020/07/02 (木) 23:24:13

Go

packege main

import "fmt"

func main(){
	fmt.Println("Hello,World!")
}
16
とくに 2020/07/03 (金) 18:12:45 修正

番外編
Windowsのデスクトップアプリケーション版(C++言語というかほぼC)

#include <Windows.h>
#include <tchar.h>

//ウィンドウプロシージャを宣言
LRESULT CALLBACK WinProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);

//エントリポイント
int WINAPI WinMain(_In_ HINSTANCE hInst,_In_opt_ HINSTANCE provInst,_In_ PSTR lpCmdLine,_In_ int nCmdShow){
	//ウィンドウクラスの定義
	WNDCLASSEX wndClass;

	wndClass.cbSize = sizeof(WNDCLASSEX);
	wndClass.style = CS_HREDRAW | CS_VREDRAW;
	wndClass.lpfnWndProc = WinProc;
	wndClass.cbClsExtra = 0;
	wndClass.cbWndExtra = 0;
	wndClass.hInstance = hInst;
	wndClass.hIcon = LoadIcon(nullptr, IDI_APPLICATION);
	wndClass.hCursor = LoadCursor(nullptr, IDC_ARROW);
	wndClass.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
	wndClass.lpszMenuName = nullptr;
	wndClass.lpszClassName = _T("window_hello");
	wndClass.hIconSm = LoadIcon(nullptr, IDI_APPLICATION);

	//ウィンドウクラスを登録
	if (RegisterClassEx(&wndClass) == 0){
		return 1;
	}

	//ウィンドウを作成
	HWND hWnd = CreateWindow(wndClass.lpszClassName, _T("ウィンドウ"), WS_OVERLAPPEDWINDOW,
		CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, nullptr, nullptr, hInst, nullptr);

	if (hWnd == nullptr){
		return 1;
	}

	ShowWindow(hWnd, nCmdShow);
	UpdateWindow(hWnd);

	//メッセージループ
	MSG msg;
	while (GetMessage(&msg, nullptr, 0, 0)){
		TranslateMessage(&msg);
		DispatchMessage(&msg);
	}

	return (int)msg.wParam;
}

//ウィンドウプロシージャ
LRESULT CALLBACK WinProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam){
	static LPCTSTR msgText = _T("Hello,World!");

	switch (msg){
	case WM_PAINT: //ウィンドウの描画
	{
		PAINTSTRUCT ps;
		HDC hdc = BeginPaint(hWnd, &ps);
		TextOut(hdc, 20, 20, msgText, lstrlen(msgText));
		EndPaint(hWnd, &ps);
		break;
	}
	case WM_DESTROY: //ウィンドウが破棄される
		PostQuitMessage(0); //メッセージループを終了させる
		break;
	}
	return DefWindowProc(hWnd, msg, wParam, lParam); //デフォルトのプロシージャ
}