Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: sortstringarray

  1. #1
    Junior Member ZaneDarklace's Avatar
    Join Date
    Feb 2014
    Location
    Lawton, OK
    Posts
    15
    My Mood
    Lonely
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default sortstringarray

    Please help me. i am working on this project and i believe that i am going the wrong way on it. it says to create a String array call ss. It will contain the following Strings in the order shown.
    {“Bill”, “Mary”, “Lee”, “Agnes”, “Alfred”, “Thomas”, “Alvin”, “Bernard”, “Ezra”,“Herman”} Using this method
    public static void sort(int a[]) //Signature
    Example:
    int b[] = {14, 2, 109, . . . 23, 5, 199};
    Arrays.sort(b);
    to sort this array and then print the contents of the
    sorted array (using a loop) from index 0 to the last. Call both your project and class,
    SortStringArray. Confine all of your code to the main method.
    The printout should look like the following:
    Agnes
    Alfred
    Alvin
    Bernard
    Bill
    Ezra
    Herman
    Lee
    Mary
    Thomas
    this is what i have so far :
    import java.io.*;
    import java.util.*;
    public class sortstringarray
    {
      public static void main(String args[])
      {
        for(int a = 0; a <= 9; a++)
        Int 0 = "Bill";
        Int 1 = "Mary";
        Int 2 = "Lee";
        Int 3 = "Agnes";
        Int 4 = "Alfred";
        Int 5 = "Thomas";
        Int 6 = "Alvin";
        Int 7 = "Bernard";
        Int 8 = "Ezra";
        Int 9 = "Herman";
        String ss[] = {a};
        Arrays.sort(ss);
        System.out.print(ss);
      }
    }
    please send me some feedback on this
    Rock On

  2. #2
    Member andbin's Avatar
    Join Date
    Dec 2013
    Location
    Italy
    Posts
    443
    Thanks
    4
    Thanked 122 Times in 114 Posts

    Default Re: sortstringarray

    Quote Originally Posted by ZaneDarklace View Post
    this is what i have so far :
    import java.io.*;
    import java.util.*;
    public class sortstringarray
    {
      public static void main(String args[])
      {
        for(int a = 0; a <= 9; a++)
        Int 0 = "Bill";
        Int 1 = "Mary";
        Int 2 = "Lee";
        Int 3 = "Agnes";
        Int 4 = "Alfred";
        Int 5 = "Thomas";
        Int 6 = "Alvin";
        Int 7 = "Bernard";
        Int 8 = "Ezra";
        Int 9 = "Herman";
        String ss[] = {a};
        Arrays.sort(ss);
        System.out.print(ss);
      }
    }
    please send me some feedback on this
    And the feedback is: this code is completely wrong and meaningless. It has so many syntax errors that it's not even compilable. You have to start with Java in another (hope better) way .....
    Andrea, www.andbin.netSCJP 5 (91%) – SCWCD 5 (94%)

    Useful links for Java beginnersMy new project Java Examples on Google Code

  3. #3
    Member
    Join Date
    Dec 2013
    Posts
    40
    My Mood
    Amazed
    Thanks
    2
    Thanked 11 Times in 11 Posts

    Default Re: sortstringarray

    Your code looks absolutely wrong. But just so I don't discourage you, i'll let you have this heads up:
    1. You only need to import the java.util package;
    2. You don't need a loop;
    3. Names like Bill, Mary, etc should be declared String;

    Finally, I strongly suggest you study some tutorial in this course as you wouldn't get anyware with this. All the best!
    Who holds the KEY to all knowledge?

  4. #4
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: sortstringarray

    Recommended reading if you have not:
    String (Java Platform SE 7 )
    Arrays (The Java™ Tutorials > Learning the Java Language > Language Basics)
    Variables (The Java™ Tutorials > Learning the Java Language > Language Basics)