Need help sorting 2 arrays linked by their indexes

I have 2 arrays that have been linked by the index of both arrays. The first array has to be sorted alphabetically, so I need a way to sort the 2nd array so that the indices match up again with the first array.
Now, I cannot change my ArrayList (i.e. TreeSet, List, etc.) since there is lots of code that would have to be changed. Here is my test code. Hopefully everyone is a fan of the television show Friends so that you can see how if I sort the firstName Array alphabetically, then I have to have the 2nd array sorted to be "linked" back to the first array based on the index. I am looking for ideas, but if you have simple code, that would be great too.
import java.util.*;
public class Test
     public static void main(String[] args)
          System.out.println("BEGIN TEST...");
Test test = new Test();
test.beginTest();
System.out.println("\nTEST COMPLETE!");
     public Test(){}
     public void beginTest()
          ArrayList firstName = new ArrayList();
          ArrayList lastName = new ArrayList();
          //Add to firstName ArrayList
          firstName.add("Ross");
          firstName.add("Chandler");
          firstName.add("Rachel");
          firstName.add("Phoebe");
          firstName.add("Joey");
          //Add to lastName ArrayList
          lastName.add("Geller");
          lastName.add("Bing");
          lastName.add("Green");
          lastName.add("Buffay");
          lastName.add("Tribbiani");
          try
               System.out.println("TESTING...\n");
               for(int index=0; index<firstName.size(); index++)
                    String first = firstName.get(index).toString();
                    String last = lastName.get(index).toString();
                    System.out.println("Hi, I am " + first + " " + last + ".");                    
          catch(Exception X) { System.out.println("EXCEPTION! "+X); X.printStackTrace(); }
}

Keeping the list in synch is conceptually easy.
Basically anything you do to the one List, you have to do to the other in order to keep them consistent.
How are you sorting your "firstnames" list?
Using the Collections.sort method, or some manual coding?
Would it be possible to change your datastructure from "parallel arrays" to "List of people objects"
iepublic class Person {
  String firstName;
  String lastName;
  public Person(String firstName, String lastName){
    this.firstName = firstName;
    this.lastName = lastName;
  // appropriate getter/setter methods
}Then you could build up your list like this:
List friends = new ArrayList();
friends.add(new Person("Ross", "Geller"));
friends.add(new Person("Chandler", "Bing"));
  ...Now when you sort the list, the last name always goes with the first name because they are in the same object.
You then write different Comparator objects to impose different orderings.
Hope this helps,
evnafets

Similar Messages

  • I need help sorting an Array.

    Hi, I need to make a program that reads a string (sentence), then it counts the number of times each letter is "typed". As an optional challenge, the teacher told us to sort the results from the most repeated, to the least.
    My program is working pretty well, here is the code:
    import java.lang.String;
    //import java.util.Collections;
    //import java.util.*;
    public class count {
         final int alpha = 66;
         int [] lower = new int [alpha];
          * @param args
         public static void main(String[] args) {
              // TODO Auto-generated method stub
              java.util.Scanner in = new java.util.Scanner (System.in);
              char current;
              final int alpha = 66;
              int [] lower = new int [alpha];
              int Spaces = 0;
    System.out.println("Enter a sentence:");
    String line = in.nextLine ();
    //int length = line.length();
    line = line.toLowerCase();
    for (int ch = 0; ch < line.length(); ch++)
    current = line.charAt(ch);
    if (current >= 'a' && current <= 'z')
    lower[current-'a']++;
    else if (current == ' ')
    Spaces ++;
    System.out.println();
    for (int letter=0; letter < lower.length;letter++)
         if (lower[letter]>0){
    System.out.print((char)(letter + 'a'));
    System.out.println(": " + lower[letter]);
         System.out.println ();
         System.out.println ("Spaces: " + Spaces);
         }[now, I want to sort the results. I tried using Arrays.sort(lower); but it doesnt work as it should. Example:
    String: Hello
    not sorted:
    e: 1
    h: 1
    l: 2
    o: 1
    Spaces: 0
    "sorted":
    : 1
    .:1
    ]:1
    ~:2
    Spaces: 0
    I would really appreciate your help.
    Thanks, J. Flemming

    Since you didn't post your Arraays.sort code, I can't
    tell what you did wrong.
    What does your array store? Element 0 is the number
    of 'a' occurences, 1 is 'b', etc?
    If so, then when you sort that, you'll have no idea
    which element corresponds to 'a'. You'll need a
    different approach for that. For instance, a class
    that encapsulates two pieces of data: character and
    number of occurences. You could then implement your
    own sort, or learn how to use Comparable/Comparator.
    Making Java
    Objects Comparable
    http://java.sun.com/docs/books/tutorial/collections/in
    terfaces/order.html
    http://www.javaworld.com/javaworld/jw-12-2002/jw-1227-
    sort.htmlAs I said in my original post, I used Arrays.sort(lower), which is probably wrong. My Arrays does work as you described, element 0 is the numer of occurrences of 'a', and 1 is the number of occurrences of 'b' and so on. Thanks for your responce. Im looking into what you said. Thanks again.
    Message was edited by:
    Flemm.John

  • Need help Sorting an Arraylist of type Object by Name

    Hey guys this is my first time posting on this forum so hopefully i do it the right way. My problem is that i am having difficulties sorting an Array list of my type object that i created. My class has fields for Name, ID, Hrs and Hrs worked. I need to sort this Array list in descending order according to name. Name is the last name only. I have used a bubble sort like this:
    public static void BubbleSort(TStudent[] x){
    TStudent temp = new TStudent();
            boolean doMore = true;
            while (doMore) {
                doMore = false;
                for (int i=0; i < x.length-1; i++) {
                   if (x.stuGetGPA() < x[i+1].stuGetGPA()) {
    // exchange elements
    temp = x[i]; x[i] = x[i+1];
    x[i+1] = temp;
    doMore = true;
    before many time to sort an array of my class TStudent according to GPA.  This time though i tried using an Array list instead of just a simple array and i can't figure out how i would modify that to perform the same task.  Then i googled it and read about the Collections.sort function.  The only problem there is that i know i have to make my own comparator but i can't figure out how to do that either.  All of the examples of writing a comparator i could find were just using either String's or just simple Arrays of strings.  I couldn't find a good example of using an Array list of an Object.
    Anyways sorry for the long explanation and any help anyone could give me would be greatly appreciated.  Thanks guys
    Edited by: Brian13 on Oct 19, 2007 10:38 PM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

    ok still having problems I have this line of code to try and all Arrays.sort
    Arrays.sort(Employee, TEmployee.FirstNameComparator);Then in my class TEmployee i have
    public static Comparator FirstNameComparator = new Comparator() {
        public int compare(Object employee, Object anotherEmployee) {
          String lastName1 = ((TEmployee) employee).getEmpName().toUpperCase();
          String lastName2 = ((TEmployee) anotherEmployee).getEmpName().toUpperCase();     
           return lastName1.compareTo(lastName2);
      };Here is the rundown of what i have for this. I have 2 classes. One is called TEmployee and that class holds fields for Name, ID, Hrs Worked, Hourly Rate. Then i have another class called myCompany that holds an ArrayList of type TEmployee. Then i have my main program in a Jframe.
    So maybe i am putting them in the wrong spots. The code in TEmployee thats make the comparator is fine. However when i try to call Arrays.sort from class myCompany i get this
    cannot find symbol
    symbol: method sort (java.util.Array list<TEmployee>.java.util.Comparator
    location: class java.util.Arrays
    I have to put the comparator in TEmployee right because thats where my fields for Name are? Do i call the arrays.sort from my main program or do i call that from the class myCompany where my ArrayList of TEmployees are stored?
    Again guys thanks for any help you could give me and if you need any code to see what else is going on just let me know.

  • I need Help with the dynamic link feature in CS3

    Hi I was wondering if anyone could help me with an issue I am having? I have the adobe cs3 master collection. Having watched tutorials on the dynamic link feature my version seems not to have the same options as those I have viewed. I wish to send my premiere video creation to encore using dynamic link, however when I click "file" and then "adobe dynamic link" the only options available are about "adobe after effects". I can export to encore however I am only alloowed to export one premiere sequence to one new encore file, I cannot create an encore file and import several premiere sequence into the same encore project. That means currently I can only have an encore creation with one premiere sequence in it, and I have no adobe dynamic link. Any help anyone could offer would be greatly appreciated.

    Thanks very much for that guys but my premiere media encoder only lets me export as: MPEG1, MPEG1-VCD, MPEG2, MPEG2 blu-ray, MPEG2-DVD, MPEG2-SVCD, H.264, H.264 blu-ray, Adobe Flash Video, Quicktime, Real Media, Windows Media. Are any of these formats DV AVI?
    Am I to export my videos direct to encore or save them elsewhere (e.g desktop). It seems that I cannot export sequences from different premiere projects to the same encore project.
    Sorry if any of these questions seem obvious, I am just new to premiere and keen to do things right from the off.
    Many thanks again guys.
    Date: Tue, 24 Nov 2009 19:32:47 -0700
    From: [email protected]
    To: [email protected]
    Subject: I need Help with the dynamic link feature in CS3
    Harm is correct.  For SD DVD, exporting as a DV AVI file from Pr will give you good results.  Encore's Automatic Transcoding will give you maximum quality for the available disc space.
    -Jeff
    >

  • Need help to find out link between process order and purchase order.

    Hi All,
    Need help to find out link between process order and purchase order.
    We have purchase order, we can find out associated process order in MD09 (No Purchase Requisition found in Purchase order). When I tired to replicate this scenario with same material in system but not able to do.
    Please suggest me what needs to check to get purchase order link to process order.. (this is not subcontracting )
    Edited by: SAP PQ on Sep 26, 2011 5:24 PM
    Thanks,
    SAP PQ
    Edited by: SAP PQ on Sep 26, 2011 5:24 PM

    MD09 is pegging. In SAP pegging is dynamic, meaning that there's no fixed link between purchase order and process order in your case.
    This is why you did not get the same result when you tried again later.
    Such a link can exist only if you do direct procurement for the order.

  • Re: Beginner needs help using a array of class objects, and quick

    Dear Cynthiaw,
    I just read your Beginner needs help using a array of class objects, and quick of Dec 7, 2006 9:25 PM . I really like your nice example.
    I also want to put a question on the forum and display the source code of my classe in a pretty way as you did : with colors, indentation, ... But how ? In html, I assume. How did you generate the html code of your three classes ? By help of your IDE ? NetBeans ? References ?
    I already posted my question with six source code classes ... in text mode --> Awful : See "Polymorphism did you say ?"
    Is there a way to discard and replace a post (with html source code) in the Sun forum ?
    Thanks for your help.
    Chavada

    chavada wrote:
    Dear Cynthiaw,
    I just read your Beginner needs help using a array of class objects, and quick of Dec 7, 2006 9:25 PM . I really like your nice example.You think she's still around almost a year later?
    I also want to put a question on the forum and display the source code of my classe in a pretty way as you did : with colors, indentation, ... But how ?Just use [code] and [/code] around it, or use the CODE button
    [code]
    public class Foo() {
      * This is the bar method
      public void bar() {
        // do stuff
    }[/code]

  • Hello guys need help with reverse array

    Need help reversing an array, i think my code is correct but it still does not work, so im thinking it might be something else i do not see.
    so far the input for the array is
    6, 25 , 10 , 5
    and output is still the same
    6 , 25 , 10 , 5
    not sure what is going on.
    public class Purse
        // max possible # of coins in a purse
        private static final int MAX = 10;
        private int contents[];
        private int count;      // count # of coins stored in contents[]
         * Constructor for objects of class Purse
        public Purse()
           contents = new int[MAX];
           count = 0;
         * Adds a coin to the end of a purse
         * @param  coinType     type of coin to add
        public void addCoin(int coinType)
            contents[count] = coinType;
            count = count + 1;
         * Generates a String that holds the contents of a purse
         * @return     the contents of the purse, nicely formatted
        public String toString()
            if (count == 0)
                return "()";
            StringBuffer s = new StringBuffer("(");
            int i = 0;
            for (i = 0; i < count - 1; ++i)
                s.append(contents[i] + ", "); // values neatly separated by commas
            s.append(contents[i] + ")");
            return s.toString();
         * Calculates the value of a purse
         * @return     value of the purse in cents
        public int value()
            int sum = 0; // starts sum at zero
            for( int e : contents) // sets all to e
                sum = sum + e; //finds sum of array
            return sum; //retur
         * Reverses the order of coins in a purse and returns it
        public void reverse()
           int countA = 0;
           int x = 0;
           int y = countA - 1;                                          // 5 - 1 = 4
           for (int i = contents.length - 1; i >=0 ; i--)                        // 4, 3 , 2, 1, 0
                countA++;                                             // count = 5
            while ( x < y)
                int temp = contents[x];
                contents[x] = contents [y];
                contents [y] = temp;
                y = y- 1;                                         // 4 , 3 , 2, 1 , 0
                x = x + 1 ;                                             // 0 , 1,  2  , 3 , 4
    }

    ok so i went ahead and followed what you said
    public void reverse()
          int a = 0;
          int b = contents.length - 1;
          while (b > a)
              int temp = contents[a];
              contents[a] = contents;
    contents [b] = temp;
    a++;
    b--;
    }and its outputting { 0, 0, 0, 0}
    im thinking this is because the main array is has 10 elements with only 4 in use so this is a partial array.
    Example
    the array is { 6, 25, 10, 5, 0, 0, 0, 0, 0, 0,}
    after the swap
    {0, 0 , 0 , 0, 0 , 0 , 5 , 10 , 25, 6}
    i need it to be just
    { 5, 10, 25, 6}
    so it is swapping the begining and end but only with zeroes the thing is i need to reverse the array without the zeroes                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Help sorting an array of objects needed please.

    I am trying to sort the array Students[] in descending order of Fees due. Using the code below I get a null pointer error at runtime. The array is not completely full, it has 20 cells, but the variable studentArrayCounter holds the number of used cells. The 'getFeesDue()' code returns an integer value.
    Any help is appreciated.
         // Sort Student Records Method
               public void sortStudentRecords()
                int loopCount = 0;
               for (loopCount = 1; loopCount < studentArrayCounter; loopCount ++)
              if(Students[loopCount].getFeesDue()>Students[loopCount-1].getFeesDue())
                   SortStudents[0]=Students[loopCount-1];
                   Students[loopCount-1]=Students[loopCount];
                   Students[loopCount]=SortStudents[0];
         }

    Also, unless the excersize is to write a sort algorigthm (which I kinda doubt) you should use Arrays.sort
    Arrays.sort(Students, new Comparator() {
      public int compare(Object o1, Object o2) {
        Student s1 = (Student) o1;
        Student s2 = (Student) o2;
        return s1.getFeesDue() - s2.getFeesDue();
    });

  • Need help sorting fil

    i have a brand new MuVo n200
    i need help, i put my cd's in and everyhting and i filled it with songs ans i can play them and everything, but i hate thats itssorted in ABC order. i cannot figure how to put them so it is in order by the CD or the bandname.
    please help.
    message me on aim if you want [email][email protected]][email protected][/url]

    To group the songs into albums or artist groups, I would definitely suggest putting all the tracks from each album/group in its own folder on your PC and put the folder on the muvo in just the same way as you would put a single mp3. The player (in normal play mode) will then play each folder all the way through before moving on to the next one alphabetically (or numerically, if you put numbers at the start of the folder names) and you can then use 'skip folder' to skip through to find the particular album or artist you're looking for. Play around with the shuffle modes too - you can shuffle within folders or just shuffle everything if you want.
    Tracks will normally be played alphabetically. To get them to play in order of track number, put numbers at the beginning of each file name. E.g.: file 'examplesong.mp3' would become '0_ examplesong.mp3' If you've got tonnes of songs and you're worried about it taking ages, the computer will do it for you! Click on 'my computer', then click on 'Muvo N200 media explorer'.. This shows the contents of your player. Choose a folder to reorder the songs in and click on it to display the songs. In the pictures along the top of the window, 4th from the right is an icon with a downward facing arrow and an A above a Z. Click on this, it's called 'custom sort'. You can then use the arrows at the bottom to change the order of your tracks to how you want them. Click OK, and they'll all be numbered in that order!
    For instructions on how to create folders in mediasource, read the thread in this link:
    http://forums.creative.com/creativelabs/board/message?board.id=dap&message.id=926
    I don't think you can put folders within folders in the muvo, but just the one layer really helps organisation.
    Hope that helps!
    x Flaneur
    PS- scroll down in the thread in the link: Jeremy CL was nice enough to give pictures in his instructions! If you'd like more help, type 'create folders' or something into the forum search as there's probably quite a lot of advice kicking about here!Message Edited by flaneur on 03-27-2005 :8 PM

  • Need help with MC with links inside

    Anyone can shine some light on trying to reproduce something
    similar to this?
    http://www.focus.ca/home.html
    What I need is how to do one of those tabs that aniamtes down
    and reveals links inside. I have been at this for days.
    I am very new to flash and need more assistance on the
    construction of this project.
    So far, I know how to make a MC and animated it for
    rollover/rollout, but the link inside won't work because the action
    for the MC is interferring with the inside button actions. So, what
    is my next step? I have my MC on one frame in the main timeline and
    need to perform all animation inside that and add buttons also?
    Would I put an Insible Button in their too?
    I need help?

    As example of a text based navbar like Roddy suggested can be seen here: Text Based Navbar. With it you can have complete control of the font (just use a Web Safe Font, color, rollover color and size. You can then copy and paste the text box to each page.
    OT

  • Need Help in opening a Link or URL

    Hi,
    I need help in opening a URL (on the same server where CLM application is deployed). I have added a Button on ToolBar and added the code. but it's not working. the same java program is working on my local system. below is the code.
    import java.io.*;
    import java.util.*;
    public class FileOpen
           public static void main(String[] args)       
                 FileOpen deleteList = new FileOpen();
                 String url="http://www.google.com/";
                   try {
                        String[] cmd = new String[4];
                        cmd[0] = "cmd.exe";
                        cmd[1] = "/C";
                        cmd[2] = "start";
                        cmd[3] = "c:
    amd_SCCMLog.txt";
                        System.out.println(" cmd"+cmd);
                        Process p = Runtime.getRuntime().exec(cmd);
                        System.out.println(" cmd1"+cmd);
                        Process process = Runtime.getRuntime().exec("notepad");
                        System.out.println(" cmd2"+cmd);
                        } catch (IOException ioe)
                             ioe.printStackTrace();
                 //System.out.println("Memberfarm: " + memberFarm);       
    Regards,
    Puneet Aggarwal

    Hi Puneet,
    What exactly are you trying to do? Can you describe where in the system you are doing it? There are different options....
    What about a document report with a link to the Web site URL you want to open?
    What about a read-only URL field on the document, populated with the URL you want to open?
    What about the desktop links channel?
    Lots of different ways to skin that cat (sorry cat lovers) ..your code looks like it might be the most difficult approach.
    -Howie Wexler
    www.craftysystems.com

  • Need Help with simple array program!

    Hi, I have just recently started how to use arrays[] in Java and I'm a bit confused and need help designing a program.
    What this program does, it reads in a range of letters specified by the user. The user then enters the letters (a, b or c) and stores these characters into an array, which the array's length is equal to the input range the user would enter at the start of the program. The program is then meant to find how many times (a,b and c) appears in the array and the Index it first appears at, then prints these results.
    Here is my Code for the program, hopefully this would make sense of what my program is suppose to do.
    import B102.*;
    class Letters
         static int GetSize()
              int size = 0;
              boolean err = true;
              while(err == true)
                   Screen.out.println("How Many Letters would you like to read in?");
                   size = Keybd.in.readInt();
                   err = Keybd.in.fail();
                   Keybd.in.clearError();
                   if(size <= 0)
                        err = true;
                        Screen.out.println("Invalid Input");
              return(size);
         static char[] ReadInput(int size)
              char input;
              char[] letter = new char[size];
              for(int start = 1; start <= size; start++)
                   System.out.println("Please enter a letter (a, b or c) ("+size+" max), enter # to stop:");
                   input = Keybd.in.readChar();
                   while((input != 'a') && (input != 'b') && (input != 'c') && (input != '#'))
                        Screen.out.println("Invalid Input");
                        System.out.println("Please enter a letter (a, b or c) ("+size+" max, enter # to stop:");
                        input = Keybd.in.readChar();
                                    while(input == '#')
                                                 start == size;
                                                 break;
                   for(int i = 0; i < letter.length; i++)
                        letter[i] = input;
              return(letter);
         static int CountA(char[] letter)
              int acount = 0;
              for(int i = 0; i < letter.length; i++)
                   if(letter[i] == 'a')
                        acount++;
              return(acount);
         static int CountB(char[] letter)
              int bcount = 0;
              for(int i = 0; i < letter.length; i++)
                   if(letter[i] == 'b')
                        bcount++;
              return(bcount);
         static int CountC(char[] letter)
              int ccount = 0;
              for(int i = 0; i < letter.length; i++)
                   if(letter[i] == 'c')
                        ccount++;
              return(ccount);
         static int SearchA(char[] letter)
              int ia;
              for(ia = 0; ia < letter.length; ia++)
                   if(letter[ia] == 'a')
                        return(ia);
              return(ia);
         static int SearchB(char[] letter)
              int ib;
              for(ib = 0; ib < letter.length; ib++)
                   if(letter[ib] == 'b')
                        return(ib);
              return(ib);
         static int SearchC(char[] letter)
              int ic;
              for(ic = 0; ic < letter.length; ic++)
                   if(letter[ic] == 'c')
                        return(ic);
              return(ic);
         static void PrintResult(char[] letter, int acount, int bcount, int ccount, int ia, int ib, int ic)
              if(ia <= 1)
                   System.out.println("There are "+acount+" a's found, first appearing at index "+ia);
              else
                   System.out.println("There are no a's found");
              if(ib <= 1)
                   System.out.println("There are "+bcount+" b's found, first appearing at index "+ib);
              else
                   System.out.println("There are no b's found");
              if(ic <= 1)
                   System.out.println("There are "+ccount+" c's found, first appearing at index "+ic);
              else
                   System.out.println("There are no c's found");
              return;
         public static void main(String args[])
              int size;
              char[] letter;
              int acount;
              int bcount;
              int ccount;
              int ia;
              int ib;
              int ic;
              size = GetSize();
              letter = ReadInput(size);
              acount = CountA(letter);
              bcount = CountB(letter);
              ccount = CountC(letter);
              ia = SearchA(letter);
              ib = SearchB(letter);
              ic = SearchC(letter);
              PrintResult(letter, acount, bcount, ccount, ia, ib, ic);
              return;
    }     Some errors i get with my program are:
    When reading in the letters to store into the array, I get the last letter I entered placed into the entire array. Also I believe my code to find the Index is incorrect.
    Example Testing: How many letters would you like to read? 3
    Enter letter (a, b or c) (# to quit): a
    Enter letter (a, b or c) (# to quit): b
    Enter letter (a, b or c) (# to quit): c
    It prints "There are no a's'" (there should be 1 a at index 0)
    "There are no b's" (there should be 1 b at index 1)
    and "There are 3 c's, first appearing at index 0" ( there should be 1 c at index 2)
    The last thing is that my code for when the user enters "#" that the input of letters would stop and the program would then continue over to the counting and searching part for the letters, my I believe is correct but I get the same problem as stated above where the program takes the character "#" and stores it into the entire array.
    Example Testing:How many letters would you like to read? 3
    Enter letter (a, b or c) (# to quit): a
    Enter letter (a, b or c) (# to quit): #
    It prints "There are no a's'" (should have been 1 a at index 0)
    "There are no b's"
    and "There are no c's"
    Can someone please help me??? or does anyone have a program simular to this they have done and would'nt mind showing me how it works?
    Thanks
    lou87.

    Without thinking too much...something like this
    for(int start = 0; start < size; start++) {
                System.out.println("Please enter a letter (a, b or c) ("+size+" max), enter # to stop:");
                input = Keybd.in.readChar();
                while((input != 'a') && (input != 'b') && (input != 'c') && (input != '#')) {
                    Screen.out.println("Invalid Input");
                    System.out.println("Please enter a letter (a, b or c) ("+size+" max, enter # to stop:");
                    input = Keybd.in.readChar();
                if(input == '#') {
                        break;
                letter[start] = input;
            }you dont even need to do start = size; coz with the break you go out of the for loop.

  • I need help with 2 arrays

    I need help with this portion of my program, it's supposed to loop through the array and pull out the highest inputted score, currently it's only outputting what is in studentScoreTF[0].      
    private class HighScoreButtonHandler implements ActionListener
               public void actionPerformed(ActionEvent e)
              double highScore = 0;
              int endScore = 0;
              double finalScore = 0;
              String tempHigh;
              String tempScore;
              for(int score = 0; score < studentScoreTF.length; score++)
              tempHigh = studentScoreTF[score].getText();
                    tempScore = studentScoreTF[endScore].getText();
              if(tempHigh.length() <  tempScore.length())
                   highScore++;
                   finalScore = Double.parseDouble(tempScore);
             JOptionPane.showMessageDialog(null, "Highest Class Score is: " + finalScore);This is another part of the program, it's supposed to loop through the student names array and pull out the the names of the students with the highest score, again it's only outputting what's in studentName[0].
         private class StudentsButtonHandler implements ActionListener
               public void actionPerformed(ActionEvent e)
              int a = 0;
              int b = 0;
              int c = 0;
              double fini = 0;
              String name;
              String score;
              String finale;
              String finalName = new String();
              name = studentNameTF[a].getText();
              score = studentScoreTF.getText();
              finale = studentScoreTF[c].getText();
              if(score.length() < finale.length())
                   fini++;     
                   name = finalName + finale;
         JOptionPane.showMessageDialog(null, "Student(s) with the highest score: " + name);
                   } Any help would be appreciated, this is getting frustrating and I'm starting to get a headache from it, lol.
    Edited by: SammyP on Oct 29, 2009 4:18 PM
    Edited by: SammyP on Oct 29, 2009 4:19 PM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

    Heres a working example:
    class Compare {
        public int getHighest(int[] set) {
            int high = set[0];
            for(int i = 0; i < set.length; i++) {
                if(set[i] > high) {
                    high = set;
    return high;

  • Need Help Regarding Dynamic Partner Link

    Hi all
    I am new to this Oracle BPEL.
    I need to configure dynamic partner link.
    need help with this.........
    any useful links.. pls.

    Hi',
    Check this
    http://blogs.oracle.com/dasoa/entry/11g_dynamic_partnerlink_example
    there are plenty like this.
    -Yatan

  • I need to sort an array of strings based on the number in each string.

    Basically, I have a directory of files that all have the same name but each with a different number on the end.
    example: image 1.jpg, image 2.jpg, etc.
    When I use the List Directory function that returns an array of strings containing the file names in the directory, they don't come out in a 1, 2, 3, order like they appear in the directory. It sorts them character by character so that they come out like: 1, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 2, 20, 21, 22 etc.
    Is there a simple way of sorting this array of strings with the file names (as above) so that they are in numerical order?

    It's a while since this thread was started, but I am sure others will have use for this so here goes:
    The in-built array sort function sorts the strings the same way DOS and Windows do. Microsoft has fixed this in the Explorer that comes with XP, however the rest of the OS(s) still sorts the old way.
    The attached "AlphaLogical String Array Sort" VIs will sort strings arrays the same way as the new XP Explorer. There are three different implementations of the sorting, one based on the Insertion sort algorithm, a Quick Sort based on recursive calls (the most elegant way, but unfortunately LabVIEW has too much overhead when doing recursive calls so this is actually a very slow alternative) and finally the fastest; a stack based Quick Sort. There is also a test VI that will show you how the different implementations perform.
    I had not used recursive calls in LV much until I made the attached quick sort and was a bit disappointed by the fact that it is so slow, but it's a good learning example...The ability to do recursive calls this way was introduced in LV7 I believe...There is an example here on the zone that shows how you can calulate a factorial by using recursive calls, however - unlike for the quick sort (normally) - recursive calls are actually not the optimal solution for that calculation.
    Message Edited by Mads on 09-13-2005 02:30 AM
    MTO
    Attachments:
    AlphaLogical Sorting.zip ‏142 KB

Maybe you are looking for

  • Help to speed up CALCULATE formula

    I am building a reporting system of production profiles for a set of assets. The key data structure is as follows: Version  Field               Action    Profile          Date          Production     RiskCategory v1          Field1         Action00  

  • Access excel sheet uploaded in library on sharepoint using sharepoint development

    Hi, I have an excel sheet which i have uploaded on sharepoint site as a library. now i want to access this excel sheet using sharepoint development(c#). Is it possible? I have one another query- I want to read excel sheet using sharepoint 2010 develo

  • How to find out if a table is in the replication process?

    Hi, I'm trying to figure out if one of the table in the database is replicated from outside. What should I do to find out this? Can anyone help me out? Thanks a lot! _meg                                                                                

  • Difference java stack and abap stack

    hello experts,                       Difference between java stack and abap stack

  • Installing Oracle 9i Personal Edition on XP

    Hi, I am trying to install 9i Personal Edition on my Dell PC running XP. It gets 2% complete and gives me an error "Invalid Staging Area. There are no top level components for Windows NT for installion in this staging area." Another problem is that I