Page 1 of 30 12311 ... LastLast
Results 1 to 10 of 297

Thread: "Hello Ubuntu" in every programming language

  1. #1
    Join Date
    Dec 2006
    Location
    Australia
    Beans
    1,097
    Distro
    Ubuntu 12.04 Precise Pangolin

    "Hello Ubuntu" in every programming language

    List made by pp., posted by LaRoza


    ================================================== ================================================== ===



    I've just been inspired by a webpage with 193 examples of "Hello World!" programs.

    I want to make something a just slightly more useful for the beginning programmer.

    Write the most concise, but clearly readable program (call it helloubuntu) according to this specification:
    1. Say: "Hi! What's your name? "
    2. User enters name.
    3. Say: "Hello, (username)! Welcome to Ubuntu!"
    You can also use a simple GUI, like a dialog box, to ask the question, input name, etc. Just make sure the code is elegant and easy-to-understand.

    You can use programming languages, markup languages, shell scripts, or even SQL statements.

    Try not to hog too many languages. Give other posters a fair go at posting their example too. If you are posting an alternative version of code for a language that has already been posted, mention that it is an alternative version.


    I'll start off:

    Ada (using normal fixed-length string)
    Code:
    with Ada.Text_IO;
    
    use Ada.Text_IO;
    
    procedure helloubuntu is
    	username : String(1..30);
    	lastchar : Integer;
    begin
    	Put_Line("Hi!  What's your name?");
    	Get_Line(username, lastchar);
    	Put_Line("Hello, " & username(1..lastchar) & "!  Welcome to Ubuntu!");
    end helloubuntu;
    Ada (using the 2005 standard's unbounded-string)
    Code:
    with Ada.Text_IO, Ada.Text_IO.Unbounded_IO, Ada.Strings.Unbounded;
    
    use Ada.Text_IO, Ada.Text_IO.Unbounded_IO, Ada.Strings.Unbounded;
    
    procedure helloubuntu is
    	username : Unbounded_String;
    begin
    	Put("Hi!  What's your name? ");
    	Get_Line(username);
    	Put_Line("Hello, " & username & "!  Welcome to Ubuntu!");
    end helloubuntu;
    Can we beat 193?
    Last edited by samjh; November 27th, 2010 at 02:29 AM.

  2. #2
    Join Date
    Jun 2006
    Beans
    47

    Re: "Hello Ubuntu" in every programming language

    BASH

    Code:
    echo -n "Hi whats your name? "
    read name
    echo "Hello $name. Welcome to Ubuntu"

  3. #3
    Join Date
    Dec 2005
    Beans
    527
    Distro
    Ubuntu 7.04 Feisty Fawn

    Re: "Hello Ubuntu" in every programming language

    C

    runningwithscissors came up with a better one. So here it is.
    Code:
    #include <stdio.h>
    
    int main()
    {
            char name[64];
            printf("Hi! What's your name? ");
            scanf("%s", &name);
            printf("Hello, %s! Welcome to Ubuntu (GNU)/Linux!\n", &name);
    
            return 0;
    }
    That is my really bad C one. Please criticize me via PM if you feel the need.
    Last edited by Note360; July 11th, 2007 at 01:47 AM. Reason: runningwithscissors came up with a simpler implementation

  4. #4
    Join Date
    May 2007
    Location
    Alexandria, VA
    Beans
    25
    Distro
    Ubuntu 7.04 Feisty Fawn

    Re: "Hello Ubuntu" in every programming language

    Perl

    Code:
    Code:
    #!/usr/bin/perl
    
    use strict;
    
    print "Hi, What is your name? ";
    chomp( my $name = <STDIN> );
    $name = ucfirst(lc($name)); # make "name" -> "Name"
    print "Hello $name, Welcome to Ubuntu!\n";
    Result:
    Code:
    [{bulldog}~]$./name.pl
    Hi, What is your name? bULlDoG
    Hello Bulldog, Welcome to Ubuntu!
    [{bulldog}~]$

    * Side note http://www.99-bottles-of-beer.net/ has examples of `99 Bottle of Beer' in every language that I can think of ( and alot that I couldn't ) ... Gives beginners some experience with conditionals and loops as well
    Last edited by bulldog060; July 10th, 2007 at 05:26 PM.

  5. #5
    Join Date
    Oct 2006
    Location
    Austin, Texas
    Beans
    2,712
    Distro
    Ubuntu 7.10 Gutsy Gibbon

    Re: "Hello Ubuntu" in every programming language

    NASM Assembly (i386)

    It could be cleaner and more optimized, I was trying to make it easy to follow.

    The command to assemble & link is at the top.

    Code:
    ; nasm helloubuntu.asm -f elf && ld helloubuntu.o -o helloubuntu
    
    section .bss
        name resb 512
    
    segment .text 
        ; Constant data:
        intro      db   "Hi! What's you're name? "
        sz_intro   equ  $-intro
        outro1     db   "Hello "
        sz_outro1  equ  $-outro1
        outro2     db   "! Welcome to Ubuntu!", 10
        sz_outro2  equ  $-outro2
        global _start
    
    ; Console in system call
    console_in:
        mov eax, 3
        mov ebx, 0
        int 0x80
    ret
    
    ; Console out system call
    console_out:
        mov eax, 4
        mov ebx, 1
        int 0x80
    ret
    
    ; Find first newline in input
    get_len:
        mov edx, 0
        get_len_loop:
            inc edx
            cmp byte [name+edx], 10
        jne get_len_loop
    ret
    
    ; Start, equivalent to C's "main"
    _start:
        mov ecx, intro
        mov edx, sz_intro
        call console_out
    
        mov ecx, name
        mov edx, 512
        call console_in
    
        mov ecx, outro1
        mov edx, sz_outro1
        call console_out
    
        mov ecx, name
        call get_len
        call console_out
    
        mov ecx, outro2
        mov edx, sz_outro2
        call console_out
    
        ; System exit call
        mov eax, 1
        int 0x80
    Last edited by Wybiral; July 10th, 2007 at 06:22 PM.

  6. #6
    Join Date
    Jan 2007
    Location
    the third world
    Beans
    Hidden!

    Re: "Hello Ubuntu" in every programming language

    Python

    Code:
    #!/usr/bin/env python
    print "Hello, " + raw_input("Hi! What's your name? ") + "! Welcome to Ubuntu!"
    Last edited by runningwithscissors; July 10th, 2007 at 06:28 PM.
    IESVS FELLAT IN INFERNVM

  7. #7
    Join Date
    Mar 2007
    Location
    Brasil ~ São Paulo
    Beans
    7
    Distro
    Ubuntu 7.04 Feisty Fawn

    Re: "Hello Ubuntu" in every programming language

    Improvements are welcome
    I'm a beginner java programmer.

    JAVA


    Code:
    import java.io.*;
    
    public class HelloUbuntu {
    	
    	public static void main(String[] args){
    		
    		System.out.println("Hi! What's your name? \n");
    
    		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    
    		String userName = null;
    
    		try{
    			userName = reader.readLine();
    		}
    		catch( IOException e ){
    			System.out.println("Ops! A problem!");
    		}
    
    		System.out.println("Hello, "+userName+" ! Welcome to Ubuntu!");
    
    	}
    }

  8. #8
    Join Date
    Jan 2006
    Location
    Grønland,Oslo
    Beans
    618

    Re: "Hello Ubuntu" in every programming language

    Pike

    The Pike programming language: http://en.wikipedia.org/wiki/Pike_%2...ng_language%29

    First, install Pike interpreter
    $ apt-cache search pike
    $ sudo apt-get install pike7.6

    Code:
    #!/usr/bin/env pike
    
    // Hello from a Pike program 
    
    void say_this(string|void msg)
    {
        if (!msg)
            write("Hello\n");
        else
            write(String.capitalize(msg) + "\n");
    }
    
    int main(int argc, array(string) argv)
    {
        string s = "hello" " " "ubuntu!"; 
    
        mixed result = catch  {
            say_this(s);
        };
    
        // result will be != NULL string object if an exception was thrown.
        if(result == 0)
            write("Ok.\n");
        else
            write("There was an error: " + result + "\n");
    
        return 0;
    }
    Save the code to "hello-ubuntu.pike" file.

    Make it executable
    $ chmod +x hello-ubuntu.pike

    Run it
    $ ./hello-ubuntu.pike
    --------------------------------------------------------

    EDIT: If you want ask user's name, then write
    Code:
       string name = Stdio.Readline()->read("Your name please:");
    Last edited by moma; July 14th, 2007 at 07:08 PM.

  9. #9
    Join Date
    Jul 2006
    Location
    Don't remember anymore
    Beans
    141
    Distro
    Ubuntu 6.06 Dapper

    Re: "Hello Ubuntu" in every programming language

    C++

    Version 1: Do not write results to file


    Code:
    #include <cstdio>
    #include <cstdlib>
    #include <iostream>
    
    using namespace std;
    
    string username = "";
    
    int main(int argc, char *argv[]);
    
    int main(int argc, char *argv[]){
        cout << "Hi! What's your name? ";
        cin >> username;
        cout << "Hello, " << username << "! Welcome to Ubuntu!\n";
        return 0;
    }

    Version 2: Write results to file

    Code:
     #include <cstdio>
    #include <cstdlib>
    #include <fstream>
    #include <iostream>
    
    using namespace std;
    
    string username = "";
    
    int main(int argc, char argv[]);
    
    int main(int argc, char *argv[]){
        cout << "Hi! What's your name? ";
        cin >> username;
        cout << "Hello, " << username << "! Welcome to Ubuntu!\n";
        ofstream userlist;
        userlist.open ("userlist", ios::app);
        userlist << username << "\n";
        userlist.close();
        return 0;
    }
    The second version keeps a log of users, one name per line.
    "Who d'you know who's lost a buttock?" --Tonks
    Linux user #430538 (Machine #335692)/Ubuntu user 7858 (Machine #9033)
    myAge.today = myAge.yesterday++

  10. #10
    Join Date
    Mar 2006
    Location
    Philadelphia, PA
    Beans
    470

    Re: "Hello Ubuntu" in every programming language

    PHP
    Code:
    #!/usr/bin/php <?php echo "Hi! Whats your name? "; $name = ucfirst(trim(fgets(STDIN))); echo "Hello, ".$name."! Welcome to ubuntu!\n"; ?>
    You need the php5-cli package to run this.
    Last edited by maddog39; September 27th, 2007 at 03:21 AM.
    Ubuntu User #: 0x2695 | Banshee 1.8/2.0 Pidgin Plugin

    Intel Q6600 @3.21, 4GB, GTX260, ArchLinux
    Lenovo IdeaPad S10, 1.6GHz Intel Atom, ArchLinux

Page 1 of 30 12311 ... LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •