Results 1 to 5 of 5
  1. #1
    Jin-enigma-PL is offline Member
    Join Date
    Feb 2009
    Posts
    3
    Rep Power
    0

    Default help with fixing my assignment.please...error

    public class SortNames3{

    public static void main(String[] args){
    }
    public static void printlist(String[] list)
    {
    for(int i=0; i<list.length;i++)
    {
    System.Out.println(args);
    }
    }
    }
    public static void SelectionSort (String[]list,)
    {

    }

    public static int findmax(String[]list,int start, int finish)
    {
    int max = 0;
    for(int i=0; i<list.length;i++)

    string current = list[i];
    string maxString = list[max];

    if(current.compareTo(maxString) >0)
    {
    max=i;
    }
    System.exit(0);
    }

    it compiles but then when names are entered to be sorted it says "exception in thread "main" java.lang.ArrayIndexOutOfBoundsException:4"
    I would fix it if i understood java more
    please help
    thanks

  2. #2
    angryboy's Avatar
    angryboy is offline Senior Member
    Join Date
    Jan 2009
    Posts
    742
    Rep Power
    6

    Default

    you don't have stuff in main(), and your {} are not matched. so i don't know how you can have an error in "main". is this the complete code?
    USE CODE TAGS--> [CODE]...[/CODE]
    Get NotePad++ (free)

  3. #3
    Jin-enigma-PL is offline Member
    Join Date
    Feb 2009
    Posts
    3
    Rep Power
    0

    Default the real code (stupid me)

    public class SortNames4{

    public static void main(String[] args){
    printlist(args);
    sortlist(args);
    printlist(args);
    }
    public static void printlist(String[] list)
    {
    for(int i=0; i<list.length;i++)
    {
    System.out.print(list[i] + " ");
    }
    }

    public static void sortlist (String[] list) {


    for( int i=list.length; i>=0; i--){
    int maxloc = findmax(list, 0, i);
    String temp = list[i];
    list[i] = list[maxloc];
    list[maxloc] = temp;
    }

    }

    public static int findmax(String[]list, int start, int finish){
    int maxsofar = 0;
    for( int i=start; i<finish;i++){

    String currString = list[i];
    String maxsoofar = list[maxsofar];
    if (currString.compareTo(maxsoofar)>0){
    maxsofar=i;

    }
    }
    return maxsofar;
    }

    }


    Sorry about that (i am totally new to this)

  4. #4
    angryboy's Avatar
    angryboy is offline Senior Member
    Join Date
    Jan 2009
    Posts
    742
    Rep Power
    6

    Default

    in sortlist():

    for( int i=list.length-1; i>=0; i--){
    USE CODE TAGS--> [CODE]...[/CODE]
    Get NotePad++ (free)

  5. #5
    Jin-enigma-PL is offline Member
    Join Date
    Feb 2009
    Posts
    3
    Rep Power
    0

    Default

    dude you are a lifesaver thanks a million (i really need extra tutorials in java in college lol)

Similar Threads

  1. GUI First Assignment-DUE 8/1/08
    By ljk8950 in forum AWT / Swing
    Replies: 2
    Last Post: 08-01-2008, 05:23 AM
  2. First GUI Assignment
    By ljk8950 in forum New To Java
    Replies: 1
    Last Post: 07-31-2008, 08:29 AM
  3. Java assignment
    By xtianah77 in forum New To Java
    Replies: 1
    Last Post: 02-18-2008, 12:54 AM
  4. Exception Error need help fixing
    By skinnybones in forum New To Java
    Replies: 2
    Last Post: 12-03-2007, 08:14 PM
  5. for Assignment plz help
    By assamhammad in forum New To Java
    Replies: 1
    Last Post: 11-06-2007, 09:35 PM

Posting Permissions

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