[閒聊] 有趣:一段小小程式碼的12個語言版本 - 討論區

[閒聊] 有趣:一段小小程式碼的12個語言版本

文章瀏覽次數 98 文章回覆數 1

coscell

coscell圖像(預設)

2020-12-13 11:32:25

From:180.176.111.5

這段程式碼執行的結果為

Language n: I am the s. So there.

其中的 n 為數字 1-12, s 為程式語言名稱。
您看哪個比較順眼?

1: bash

#!/bin/sh
language=1
echo "Language $language: I am the shell. So there."

2: C

#include <stdio.h>
int main(int argc, char *argv[]) {
 int language = 2;
 printf("Language %d: I am C! See? Si!\n", language);
 return 0;
}

3: C++

#include <iostream>
using namespace std;
int main() {
 int language = 3;
 cout << "Language " << language << \
    ": I am C++!  Pay no attention to my little brother!" << \
    endl;
 return(0);
}

4: Java

public class Anecdote {
 public static void main (String[] args) {
     int language = 4;
     System.out.format("Language %d: I am Java! So there!\n", language);
 }
}

5: Perl

my $language = 5;
print "Language $language: I am Perl, the camel of languages.\n";

6: rUBY

language = 6
puts "Language #{language}: I am Ruby, ready and aglow."

7: PHP

<?PHP
$language = 7;
echo "Language $language: I am PHP, a language and palindrome.\n";
?>

8: Go

package main

import "fmt"

func main() {
  language := 8
  fmt.Printf("Language %d: Hey, ho, let's Go!\n", language)
}

9: Rust

fn main() {
 println!("Language {}: Rust here!", 9)

10: Python

language = 10
print(f"Language {language}: I am Python. What's for supper?")

11: JavaScript

let language = 11;
document.write(`Language ${language}: 我是 JavaScript! 迢迢大陸通羅馬。`);

12: AutoIt3

$language = 12
MsgBox(0, "Language " & $language & ":", "我是 AutoIt3. 這是一個對話方塊。")

留言

#1

特種兵

特種兵圖像(預設)

2020-12-14 09:23:43

From:211.23.21.202

自己比較熟的語言看起來就會比較順眼