【小测验】你能看出这是哪种语言写的程序吗?

世界上存在的编程语言有上百种,有的非常流行,有的默默无闻。有的适合商用,有的适合教学,有的适合玩耍。初学程序员可能只知道一两种语言,但随着经历越多,学的编程语言种类越多。懂多少种编程语言可以作为一个程序员能力大小的重要标准。如果你想知道自己的实力,请测一下自己,这里一共有12题,看看能选对几种?

1、

#include 

 int main()
 {
 	std::cout << "Hello, World.";
 }
    1. java
    2. python
    3. C++

2、

#!/bin/sh
 echo "Hello World"
    1. ruby
    2. shell
    3. C语言

3、

>>> def fib(n):
>>>     a, b = 0, 1
>>>     while a < n:
>>>         print(a, end=' ')
>>>         a, b = b, a+b
>>>     print()
>>> fib(1000)
    1. JavaScript
    2. Objective C
    3. Python

4、

 public class Hello {
  	public static void main(String []args) {
 		System.out.println("Hello World");
  	}
 }
    1. Java
    2. Lisp
    3. C语言

5、

# The Greeter class
class Greeter
  def initialize(name)
    @name = name.capitalize
  end

  def salute
    puts "Hello #{@name}!"
  end
end

# Create a new object
g = Greeter.new("world")

# Output "Hello World!"
g.salute
    1. JavaScript
    2. Ruby
    3. Objective C

6、

package main

import "fmt"

func main() {
	fmt.Println("Hello, 世界")
}
    1. C#
    2. Objective C
    3. Go语言

7、

$pizza  = "piece1 piece2 piece3 piece4 piece5 piece6";
$pieces = explode(" ", $pizza);
echo $pieces[0]; // piece1
echo $pieces[1]; // piece2
    1. Scala
    2. PHP
    3. JavaScript

8、

#import 
 
int main(int argc, char *argv[]) {
 
    @autoreleasepool {
        NSLog(@"Hello World!");
    }
 
   return 0;
}
    1. Objective C
    2. C语言
    3. Clojure

9、

(defun should-be-constant ()
  '(one two three))
 
(let ((stuff (should-be-constant)))
  (setf (third stuff) 'bizarre))   ; bad!
 
(should-be-constant)   ; returns (one two bizarre)
    1. Perl
    2. Lisp
    3. Scala

10、

class Hello {
 	static void Main() {
  		System.Console.Write("Hello World");
 	}
 }
    1. C#
    2. JavaScript
    3. Android Java

11、

var http = require('http');
http.createServer(function (req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end('Hello World\n');
}).listen(1337, '127.0.0.1');
console.log('Server running at http://127.0.0.1:1337/');
    1. Perl
    2. Bash
    3. node.js

12、

Imports System.Console
Module Program
    Sub Main() 
        Dim rows As Integer
        Dim current = 1
        For row = 1 To rows
            For column = 1 To row 
                Write("{0,-2} ", current) 
                current += 1
            Next
            WriteLine()
        Next 
    End Sub
End Module
    1. Pascal
    2. Swift
    3. Visual Basic .NET

原文:http://www.vaikan.com/codes-writen-by-programming-languages/

Sidebar