2012年5月28日 星期一

001 Hello world


















=====
C: main.c
=====

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char** argv)
{
    printf("Hello world!\n");

    printf("Press Any Key to Exit: ");
    char cTmp = 0;
    cTmp = getchar();
    /*
    int getchar ( void ); */
    //The character read is returned as an int value.

    return 0;
}

=====
PERL: hello_world.pl
=====

#!/usr/bin/perl -w

use strict;

main();

sub main()
{
    printf("Hello world!\n");
 
    print 'Press Enter to Exit: ';  
    my $strTmp = <stdin>;
    #<stdin> stands for standard input. It can be abbreviated by using simple &lt;&gt;.
 
    return 0;
}

=====
PYTHON: hello_world.py
=====

#!/usr/bin/python

def main():
    print "Hello world!"
    print 'Press Enter to Exit: ',
    # "" equals to '' in python
    # use "," in the end to refuse new-line
    strTmp = raw_input()

main()

=====
JAVA: hello_world.java
=====

import java.io.*;

public class hello_world
{
    public static void main(String[] args) throws IOException
    {
        System.out.println("Hello world!");
     
        System.out.printf("Press Enter to Exit: ");
        // use BufferedReader to get input from STDIN
        BufferedReader bufTmp = new BufferedReader(new InputStreamReader(System.in));
        String strTmp;
        strTmp = bufTmp.readLine();
    }
}


沒有留言:

張貼留言