Results 1 to 5 of 5
  1. #1
    Teclis is offline Member
    Join Date
    Mar 2011
    Posts
    48
    Rep Power
    0

    Default Return multiply array changes?

    Java Code:
       public static void sortDatabase(int numRecords, String[] pitchNameF,
          String[] pitchNameL, int[] shutOutArr, double[] eraArr)
       {
          int smallest; //variable to hold the index of the smallest element
    
          String temp, temp2; //a temporary variable to use when swapping the elements
          int temp3;
          double temp4;
          for(int i = 0; i < numRecords; i++)
    
          {
    
             smallest = i;
    
             for(int j = i; j < numRecords; j++)//loop to find the smallest element
             {
                if(pitchNameL[j] < pitchNameL[smallest])
                   smallest = j;
             }
             temp = pitchNameL[i];
             pitchNameL[i] = pitchNameL[smallest];
             pitchNameL[smallest] = temp;
             temp2 = pitchNameF[i];
             pitchNameF[i] = pitchNameF[smallest];
             pitchNameF[smallest] = temp2;
             temp3 = shutOutArr[i];
             shutOutArr[i] = shutOutArr[smallest];
             shutOutArr[smallest] = temp3;
             temp4 = eraArr[i];
             eraArr[i] = eraArr[smallest];
             eraArr[smallest] = temp4;
            }
            return pitchNameL, pitchNameF, shutOutArr, eraArr;
       }
    So, UNIX says my return statement isn't legal. So, how can I work that?

  2. #2
    subith86 is offline Senior Member
    Join Date
    Jan 2011
    Location
    Bangalore, India
    Posts
    102
    Rep Power
    0

    Default

    your function's return type is void. how do you expect it to return something.

  3. #3
    Teclis is offline Member
    Join Date
    Mar 2011
    Posts
    48
    Rep Power
    0

    Default

    Yeah, I completely forgot.


    My next predicament is doing the (java.lang.string < java.lang.string). I need it to go the way it is, but I don't know the string "<" variable. Would I use .compareTo()? I'm really unsure about how to work specifically with that.

  4. #4
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,807
    Rep Power
    10

    Default

    Yes you use the compareTo method to compare if one String is lexigraphically before another. That method returns an int which you can then use in a logical statement.

  5. #5
    Teclis is offline Member
    Join Date
    Mar 2011
    Posts
    48
    Rep Power
    0

    Default

    I did it, and it works- sort of. I'll be doing more debugging tomorrow; but it sorted it and then placed it in...backwards order? What is supposed to be #4 is in #1, 3 in 2, 2 in 3, 1 in 4. So, I'm on the cusp of it!

Similar Threads

  1. Filling an array from the return value of the function
    By alex1988 in forum Java Applets
    Replies: 7
    Last Post: 02-02-2011, 10:29 AM
  2. How to return Jobject array in jni
    By mahesh.gmb in forum Advanced Java
    Replies: 0
    Last Post: 02-02-2011, 09:23 AM
  3. return array
    By rfviki in forum New To Java
    Replies: 2
    Last Post: 11-03-2010, 02:05 PM
  4. return array problem
    By doha786 in forum New To Java
    Replies: 3
    Last Post: 03-30-2010, 05:08 PM
  5. How do i return a random String from an array?
    By Grendel0 in forum New To Java
    Replies: 9
    Last Post: 03-11-2010, 11:11 AM

Posting Permissions

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