Help with using Arrays

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • JoeMugsy
    New Member
    • Jan 2007
    • 3

    #1

    Help with using Arrays

    Hello world. I am new to JAVA and need help developing a program in which one can enter names from the keyboard and output those names in alphabetical order. Im thinking it involves arrays but i really dont have good undrstanding or much experience with the program.
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Originally posted by JoeMugsy
    Hello world. I am new to JAVA and need help developing a program in which one can enter names from the keyboard and output those names in alphabetical order. Im thinking it involves arrays but i really dont have good undrstanding or much experience with the program.
    If you want to use an array then you need the user to enter the number of names they are going to enter first. Do you know how to take input from the user into a program?

    Comment

    • JoeMugsy
      New Member
      • Jan 2007
      • 3

      #3
      Originally posted by r035198x
      If you want to use an array then you need the user to enter the number of names they are going to enter first. Do you know how to take input from the user into a program?

      i think. would you first use something like this to get the number of names

      System.out.prin t("How many names would you like to enter:");
      amount = console.readLin e();
      temp= Integer.parseln t(amount)

      how do you get the program to know how many to expect.and would i use the same format to take input for the names. i know i would have to replace integer on the third line with a code to read words.

      Comment

      • r035198x
        MVP
        • Sep 2006
        • 13225

        #4
        Originally posted by JoeMugsy
        i think. would you first use something like this to get the number of names

        System.out.prin t("How many names would you like to enter:");
        amount = console.readLin e();
        temp= Integer.parseln t(amount)

        how do you get the program to know how many to expect.and would i use the same format to take input for the names. i know i would have to replace integer on the third line with a code to read words.
        You've got it.

        Now you declare the array as
        Code:
         String[] names = new String[temp];
        and use a loop to take all the names and put them into the array.

        Comment

        • JoeMugsy
          New Member
          • Jan 2007
          • 3

          #5
          Originally posted by r035198x
          You've got it.

          Now you declare the array as
          Code:
           String[] names = new String[temp];
          and use a loop to take all the names and put them into the array.

          ok. i will get back to you as soon as I run into any other problems. THANKS

          Comment

          Working...