small program in Java language

Discussion in 'Programming' started by stars, Jun 9, 2007.

  1. #1
    Could any one help me to create a program that can do the following thing:

    for example : I have a file name.txt contain

    bell
    things
    bob
    
    Code (markup):
    after the program run , I get

    
    bell
    bob
    things
    Code (markup):
    this program just arrange the words according to the alphabet.

    Could any one help me to do this?

    Thank you
     
    stars, Jun 9, 2007 IP
  2. mattcch2007

    mattcch2007 Peon

    Messages:
    562
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    sort routine at sun.com or java.com or a search with 'sort on java' on googxx
    need 4 parts, but depend on it is a java application(.exe/.sh) or java applets(.class)

    1. file manage i/o=> create, open or read/write
    2. an array for holding 3 strings and
    3. check for first char in each elements in the array of string
    4. most important: it seem a assignment/homework, suggest try harder:D:D:D:D
     
    mattcch2007, Jun 10, 2007 IP
  3. CygnetGames

    CygnetGames Peon

    Messages:
    43
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Like mattcch2007 said, this sounds like a homework assignment so i'm not gong to give you any code, but this is the general structure you want:

    Open the input file
    Read in each line into an array
    Sort the array
    Open the output file
    Write each element from the array into the output file

    The libaray java.io provides facilities for opening/reading/writing files. I'm not sure where you would find a sorting function, but maybe java.lang or java.util.

    Good luck with it.
     
    CygnetGames, Jun 10, 2007 IP
  4. ProgrammersTalk

    ProgrammersTalk Peon

    Messages:
    684
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #4
    I'm not going to tell you, but hopefully this TUTORIAL that one of our user created would help :) You'll just need to implement your logic.

    HINT: use StringTokenizer :D
     
    ProgrammersTalk, Jun 11, 2007 IP