Sorting a String Array in alpha order (Using ArrayList)

Hello all!
I am pretty new to Java and am trying to do a, seemingly, simple task; but cannot get the syntax right. I am trying to sort an ArrayList in aplha order based off of the variable String Product. Any help would be awesome!
First Class:
//This program stores all of the variables for use in Inventory.java
public class Vars {
     // defining all variables
     private String product;
     private String prodCode;
     private double price;
     private double invCount;
     // Begin listing getters for class
     public Vars(String product) {
          this.product = product;
     public String getProdCode() {
          return prodCode;
     public String getProduct() {
          return product;
     public double getPrice() {
          return price;
     public double getInvCount() {
          return invCount;
     // Declaring the total variable
     public double total() {
          return invCount * price;
     // Begin listing setters for variables
     public void setProduct(String product) {
          this.product = product;
     public void setProdCode(String prodCode) {
          this.prodCode = prodCode;
     public void setInvCount(double invCount) {
          this.invCount = invCount;
     public void setPrice(double price) {
          this.price = price;
Second Class:
//This program will use the variables stored in Vars.java
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class Inventory {
     public static void main(String args[]) {
          Scanner input = new Scanner(System.in);
          //defining and declaring local variables
          String exit;
          int counter;
          double gtotal;
          exit = "exit";
          counter = 0;
          gtotal = 0;
          //beginning message and beginning of the loop
          System.out.print("Welcome to the Inventory Contol System\nPlease enter the Product name: ");
          System.out.println();
          System.out.println("When finished entering in the data, please enter EXIT in place of Product name.");
          String name = input.next();
          List<Vars> var = new ArrayList<Vars>(); //creating arraylist object
          //loop while exit is not entered, exit loop once exit is typed into product variable
          while (name.compareToIgnoreCase(exit) != 0) {
               Vars vars = new Vars(name); //calling Vars methods
               counter = counter ++;
               System.out.println("Please enter the Product Code: ");
               vars.setProdCode(input.next());
               System.out.println("Inventory Count: ");
               vars.setInvCount(input.nextDouble());
               //Making sure that the value entered is a positive one
               if(vars.getInvCount() < 0){
                    System.out.println("Please enter a positive number: ");
                    vars.setInvCount(input.nextDouble());
               System.out.println("Price per product:");
               vars.setPrice(input.nextDouble());
               //Making sure that the value entered is a positive one
               if(vars.getPrice() < 0) {
                    System.out.println("Please enter a positive number: ");
                    vars.setPrice(input.nextDouble());
               System.out.println("Please enter the next Product name, or enter EXIT: ");
               name = input.next();
               gtotal += vars.total(); //calculation for Grand Total of all products entered
               var.add(vars);
               static void slectionSort(int[] product) {
               for (int lastPlace = product.length-1; lastPlace > 0; lastPlace--) {
               int maxLoc = 0;
               for (int j = 1; j <= lastPlace; j++) {
               if (product[j] > product[maxLoc]) {
               maxLoc = j;
               int temp = product[maxLoc];
               product[maxLoc] = product[lastPlace];
               product[lastPlace] = temp;
          //Sorting loop function will go here, before the information is displayed
          //Exit message and array list headers
          System.out.print("Thank you for using the Inventory program.\nHave a wonderful day.\n");
          System.out.printf("Code\tProduct\tCount\tPrice\tTotal\n");
          System.out.println();
          //For loop to display all entries via an ArrayList
          for (Vars vars : var) {
               System.out.printf("%5s\t%5s\t%.01f\t$%.02f\t$%.02f\n\n", vars.getProdCode(),
                         vars.getProduct(), vars.getInvCount(), vars.getPrice(),vars.total());
          //Displays the amount of entries made and Grand Total of all products entered
          System.out.println();
          System.out.printf("The number of products entered is %d\n", var.size());
          System.out.printf("The Grand Total cost for the products entered is $ %s\n", gtotal);
          System.out.println();
}

go through below links, you can easily understand how to sort lists.
http://www.onjava.com/lpt/a/3286
http://java.sun.com/docs/books/tutorial/collections/interfaces/order.html
http://www.javaworld.com/javaworld/jw-12-2002/jw-1227-sort.html

Similar Messages

  • How to Display string array in jsp page using netui-data:repeater tag ??

    hi,
    I am trying to display a string array in a table using the netui-data:repeater tag.
    I have to use a page flow controller Array(1 Dimensional) to be displayed in the jsp.
    Can any one tell me how to print the array in a table of 3rows & 5 columns.
    Here is the code on which I am crrently working on.
    <netui-data:repeater dataSource="{pageFlow.strWorkObject_Array}">
    <netui-data:repeaterHeader>
    <table cellpadding="4" border="1" class="tablebody">
    </netui-data:repeaterHeader>
    <netui-data:repeaterItem>
    <tr>
    <td><netui:label value="{container.item}" >
    </netui:label></td>
    <td><netui:label value="{container.item}">
    </netui:label></td>
    <td><netui:label value="{container.item}">
    </netui:label></td>
    </tr>
    </netui-data:repeaterItem>
    <netui-data:repeaterFooter>
    </table>
    </netui-data:repeaterFooter>
    </netui-data:repeater>

    weblogic.developer.interest.workshop
    Mansoor Naseem wrote:
    I would like to know where the pageflow newsgroup is.
    These are all the groups in weblogic.developer.interest:
    weblogic.developer.interest.60beta.* (5 groups) weblogic.developer.interest.management
    weblogic.developer.interest.61beta.* (2 groups) weblogic.developer.interest.misc
    weblogic.developer.interest.clustering.* (1 group) weblogic.developer.interest.performance
    weblogic.developer.interest.commerce weblogic.developer.interest.personalization
    weblogic.developer.interest.ejb.* (3 groups) weblogic.developer.interest.portal
    weblogic.developer.interest.environment weblogic.developer.interest.rmi-iiop
    weblogic.developer.interest.jdbc weblogic.developer.interest.security
    weblogic.developer.interest.jms weblogic.developer.interest.servlet
    weblogic.developer.interest.jndi weblogic.developer.interest.tools
    weblogic.developer.interest.jsp weblogic.developer.interest.weblogicenterprise
    MN

  • Sorting app on ipad2 in alpha order

    Sorting apps on ipad2 in alpha order yes or no

    Settings > General > Reset > Reset Home Screen Layout may do it in alphabetical order (not sure whether the built-in apps will be shown first) - I've never tried it.

  • Display string array in a table using netui-data:repeater tags

    hi,
    I am trying to display a string array in a table using the netui-data:repeater tag.
    I have to use a page flow controller Array(1 Dimensional) to be displayed in the jsp.
    Can any one tell me how to print the array in a table of 3rows & 5 columns.
    Here is the code on which I am crrently working on.
    <netui-data:repeater dataSource="{pageFlow.strWorkObject_Array}">
    <netui-data:repeaterHeader>
    <table cellpadding="4" border="1" class="tablebody">
    </netui-data:repeaterHeader>
    <netui-data:repeaterItem>
    <tr>
    <td><netui:label value="{container.item}" >
    </netui:label></td>
    <td><netui:label value="{container.item}">
    </netui:label></td>
    <td><netui:label value="{container.item}">
    </netui:label></td>
    </tr>
    </netui-data:repeaterItem>
    <netui-data:repeaterFooter>
    </table>
    </netui-data:repeaterFooter>
    </netui-data:repeater>

    weblogic.developer.interest.workshop
    Mansoor Naseem wrote:
    I would like to know where the pageflow newsgroup is.
    These are all the groups in weblogic.developer.interest:
    weblogic.developer.interest.60beta.* (5 groups) weblogic.developer.interest.management
    weblogic.developer.interest.61beta.* (2 groups) weblogic.developer.interest.misc
    weblogic.developer.interest.clustering.* (1 group) weblogic.developer.interest.performance
    weblogic.developer.interest.commerce weblogic.developer.interest.personalization
    weblogic.developer.interest.ejb.* (3 groups) weblogic.developer.interest.portal
    weblogic.developer.interest.environment weblogic.developer.interest.rmi-iiop
    weblogic.developer.interest.jdbc weblogic.developer.interest.security
    weblogic.developer.interest.jms weblogic.developer.interest.servlet
    weblogic.developer.interest.jndi weblogic.developer.interest.tools
    weblogic.developer.interest.jsp weblogic.developer.interest.weblogicenterprise
    MN

  • Newbie trying to sort 2D string array

    Dear all,
    After read some book chapters, web sites including this, I still don't get the point.
    If I have a file like,
    1 aaa 213 0.9
    3 cbb 514 0.1
    2 abc 219 1.3
    9 bbc 417 10.4
    8 dee 887 2.1
    9 bba 111 7.1
    and I load into memory as a String[][]
    here comes the problem, I sort by column 1 (aaa,...,bba) using an adaptation of the Quicksort algorithm for 2D arrays
    * Sort for a 2D String array
    * @param a an String 2D array
    * @param column column to be sort
    public static void sort(String[][] a, int column) throws Exception {
    QuickSort(a, 0, a.length - 1, column);
    /** Sort elements using QuickSort algorithm
    static void QuickSort(String[][] a, int lo0, int hi0, int column) throws Exception {
    int lo = lo0;
    int hi = hi0;
    int mid;
    String mitad;
    if ( hi0 > lo0) {
    /* Arbitrarily establishing partition element as the midpoint of
    * the array.
    mid = ( lo0 + hi0 ) / 2 ;
    mitad = a[mid][column];
    // loop through the array until indices cross
    while( lo <= hi ) {
    /* find the first element that is greater than or equal to
    * the partition element starting from the left Index.
    while( ( lo < hi0 ) && ( a[lo][column].compareTo(mitad)<0))
    ++lo;
    /* find an element that is smaller than or equal to
    * the partition element starting from the right Index.
    while( ( hi > lo0 ) && ( a[hi][column].compareTo(mitad)>0))
    --hi;
    // if the indexes have not crossed, swap
    if( lo <= hi )
    swap(a, lo, hi);
    ++lo;
    --hi;
    /* If the right index has not reached the left side of array
    * must now sort the left partition.
    if( lo0 < hi )
    QuickSort( a, lo0, hi, column );
    /* If the left index has not reached the right side of array
    * must now sort the right partition.
    if( lo < hi0 )
    QuickSort( a, lo, hi0, column );
    * swap 2D String column
    private static void swap(String[][] array, int k1, int k2){
    String[] temp = array[k1];
    array[k1] = array[k2];
    array[k2] = temp;
    ----- end of the code --------
    if I call this from the main module like this
    import MyUtil.*;
    public class kaka
    public static void main(String[] args) throws Exception
    String[][]a = MyUtil.fileToArray("array.txt");
    MyMatrix.printf(a);
    System.out.println("");
    MyMatrix.sort(a,1);
    MyMatrix.printf(a);
    System.out.println("");
    MyMatrix.sort(a,3);
    MyMatrix.printf(a);
    for the first sorting I get
    1 aaa 213 0.9
    2 abc 219 1.3
    9 bba 111 7.1
    9 bbc 417 10.4
    3 cbb 514 0.1
    8 dee 887 2.1
    (lexicographic)
    but for the second one (column 3) I get
    3 cbb 514 0.1
    1 aaa 213 0.9
    2 abc 219 1.3
    9 bbc 417 10.4
    8 dee 887 2.1
    9 bba 111 7.1
    this is not the order I want to apply to this sorting, I would like to create my own one. but or I can't or I don't know how to use a comparator on this case.
    I don't know if I am rediscovering the wheel with my (Sort String[][], but I think that has be an easy way to sort arrays of arrays better than this one.
    I've been trying to understand the Question of the week 106 (http://developer.java.sun.com/developer/qow/archive/106/) that sounds similar, and perfect for my case. But I don't know how to pass my arrays values to the class Fred().
    Any help will be deeply appreciated
    Thanks for your help and your attention
    Pedro

    public class StringArrayComparator implements Comparator {
      int sortColumn = 0;
      public int setSortColumn(c) { sortColumn = c; }
      public int compareTo(Object o1, Object o2) {
        if (o1 == null && o2 == null)
          return 0;
        if (o1 == null)
          return -1;
        if (o2 == null)
          return 1;
        String[] s1 = (String[])o1;
        String[] s2 = (String[])o2;
        // I assume the elements at position sortColumn is
        // not null nor out of bounds.
        return s1[sortColumn].compareTo(s2[sortColumn]);
    // Then you can use this to sort the 2D array:
    Comparator comparator = new StringArrayComparator();
    comparator.setSortColumn(0); // sort by first column
    String[][] array = ...
    Arrays.sort(array, comparator);I haven't tested the code, so there might be some compiler errors, or an error in the logic.

  • Sorting 2D string array

    Hi I am new to labview. I want to sort my 2D string array by col 1. But I dont know how to sort it perfectly. My sorted array will be something like this.
    Col 1
    A1
    A2
    A3
    A4
    A5
    A6
    A7
    A8
    A9
    A10
    A11

    duplicate, see: http://forums.ni.com/ni/board/message?board.id=170&thread.id=317581&jump=true
    LabVIEW Champion . Do more with less code and in less time .

  • Sort an String Array

    Im having trouble sorting an Array. Before i add my new post to a[0] I would like to push all values one step. So value of a[0] will be stored in a[1] and value of [1] will be stored in [2] before a[0] = new value.
    I haven found a way yet, anyone else?
    Sebastian Green

    Hmm, I worked my own way of handle it. Like this:
    for (int i=4; i >= 0 ; i--) {
                   if (i==0){
                        a[i] = getNewData();
                   } else {
                        a[i] = a[i-1];
                 }Which one is best? I could set the "int=4" dynamiclly . But why should I use Vector? I thought that it would be better with a String[]. Then I have set the amount of memory to use for my Array? Or is is better to store it in an Vector and call New Vector () every round so the size dosent get large then it has to?

  • String Array Sorting

    Question 1. Anybody know how to easily sort a string array?
    Question 2. Is there any good data base management VI's out there anywhere?
    Thank you

    > Question 1. Anybody know how to easily sort a string array?
    >
    There is this icon in the Array palette called Sort 1D Array. You might want
    to give it a try.
    > Question 2. Is there any good data base management VI's out there anywhere?
    >
    There may be some freebie stuff floating around, but I know that NI has
    an SQL add-on for communicating with most standard databases. As mentioned
    in a previous posting this morning, you can also use ActiveX if that is
    more convenient/easier for you. From my experience, most people find the
    SQL approach easier once they get past the three letter acronym.
    Greg McKaskle

  • Sort and Object array of Arrays

    Hi,
    I have an object array that contains a String[] and an int[].
    Object[String[], int[]]
    The values in the Strings array must be in the same position in the array as those in the int array i.e
    String [0] is the string representation of int[0].
    Its for a bar chart.
    That is all working beautifully.
    Now however I want to sort the int array in descending order by the value of the ints in the array and thus the order or the String array has to mirror this.
    I am using a comparator to do this but it just wont work. I'm sure this is the way but how should it look?
    Has anybody got any ideas?
    Thanks in advance,
    L.

    use the bubblesort:
        for (int i = a.length; --i >= 0; ) {
            for (int j = 0; j < i; j++) {
                if (a[j][1] > a[j+1][1]) {
                    int temp = a[j];
                    a[j] = a[j + 1];
                    a[j + 1] = temp;
        }

  • Trying to print the date arrays in reverse order....

    Hi,
    I'm trying to print the dates in the arrays in reverse order using the for loop, but its not working and i think ive got something in the wrong order perhaps the constructor or method. Or do i need to define 'a', because i tried it and i couldn't unless, probably because i was putting the wrong code for it.
    Thanks for your help
    public class Array
      public static void main(String[] args)
              a[0] = new Date(2, " January ", 2005)
              a[1] = new Date(3, " February ", 2005)
              a[2] = new Date(21, " March ", 2005)
              a[3] = new Date(28, " April ", 2005)
                                   printDate();
    class Date
      public int day;
      public String month;
      public int year;
      public Date(int d, String m, int y)
        day = d;
        month = m;
        year = y;
      public void printDate()
      for (int i = a.length - 1; i >= 0; i--)
                  System.out.println(a);

    I don't see where this 'a' variable is declared anywhere, so what did you expect it to do? Also, you can't just call Date's printDate method from your Array class like that. You really need to start with the java tutorials or take a course. The forums aren't going to effectively teach you the very basics.

  • Reading & writing to file using ArrayList String incorrectly (2)

    I have been able to store two strings (M44110|T33010, M92603|T10350) using ArrayList<String>, which represent the result of some patient tests. Nevertheless, the order of these results have been stored correctly.
    E.g. currently stored in file Snomed-Codes as -
    [M44110|T33010, M92603|T10350][M44110|T33010, M92603|T10350]
    Should be stored and printed out as -
    M44110|T33010
    M92603|T10350
    Below is the detail of the source code of this program:
    import java.io.*;
    import java.io.IOException;
    import java.lang.String;
    import java.util.regex.*;
    import java.util.ArrayList;
    public class FindSnomedCode {
        static ArrayList<String> allRecords = new ArrayList<String>();
        static public ArrayList<String> getContents(File existingFile) {
            StringBuffer contents = new StringBuffer();
            BufferedReader input = null;
            int line_number = 0;
            int number_of_records = 0;
            String snomedCodes = null;
            ArrayList<String> complete_records = new ArrayList<String>();
            try {
                input = new BufferedReader( new FileReader(existingFile) );
                String current_line = null;
                while (( current_line = input.readLine()) != null) {
                    // Create a pattern to match for the "\"
                    Pattern p = Pattern.compile("\\\\");
                    // Create a matcher with an input string
                    Matcher m = p.matcher(current_line);
                    boolean beginning_of_record = m.find();
                    if (beginning_of_record) {
                        line_number = 0;
                        number_of_records++;
                    } else {
                        line_number++;
                    if ( (line_number == 2) && (current_line.length() != 0) ) {
                        snomedCodes = current_line;
                        System.out.println(snomedCodes);
                        complete_records.add(current_line);
            catch (FileNotFoundException ex) {
                ex.printStackTrace();
            catch (IOException ex){
                ex.printStackTrace();
            finally {
                try {
                    if (input!= null) {
                        input.close();
                catch (IOException ex) {
                    ex.printStackTrace();
            return complete_records;
        static public void setContents(File reformatFile, ArrayList<String> snomedCodes)
                                     throws FileNotFoundException, IOException {
           Writer output = null;
            try {
                output = new BufferedWriter( new FileWriter(reformatFile) );
                  for (String index : snomedCodes) {
                      output.write( snomedCodes.toString() );
            finally {
                if (output != null) output.close();
        static public void printContents(File existingFile) {
            StringBuffer contents = new StringBuffer();
            BufferedReader input = null;
            int line_number = 0;
            int number_of_records = 0;
            String snomedCodes = null;
            try {
                input = new BufferedReader( new FileReader(existingFile) );
                String current_line = null;
                while (( current_line = input.readLine()) != null)
                    System.out.println(current_line);
            catch (FileNotFoundException ex) {
                ex.printStackTrace();
            catch (IOException ex){
                ex.printStackTrace();
            finally {
                try {
                    if (input!= null) {
                        input.close();
                catch (IOException ex) {
                    ex.printStackTrace();
        public static void main (String args[]) throws IOException {
            File currentFile = new File("D:\\dummy_patient.txt");
            allRecords = getContents(currentFile);
            File snomedFile = new File( "D:\\Snomed-Codes.txt");
            setContents(snomedFile, allRecords);
            printContents(snomedFile);
    }There are 4 patient records in the dummy_patient.txt file but only the 1st (M44110|T33010) & 3rd (M92603|T10350) records have results in them. The 2nd & 4th records have blank results.
    Lastly, could someone explain to me the difference between java.util.List & java.util.ArrayList?
    I am running Netbeans 5.0, jdk1.5.0_09 on Windows XP, SP2.
    Many thanks,
    Netbeans Fan.

    while (snomedCodes.iterator().hasNext())
      output.write( snomedCodes.toString() );
    }Here you have some kind of a list or something (I couldn't stand to read all that unformatted code but I suppose you can find out). It has an iterator which gives you the entries of the list one at a time. You keep asking if it has more entries -- which it does -- but you never get those entries by calling the next() method, so it always has all the entries still available.
    And your code inside the loop is independent of the iterator, so it's rather pointless to iterate over the entries and output exactly the same data for each entry. Even if you were iterating correctly.

  • DateTime String array in Graph

    Greetings.
    I tried to plot DateTime string array VS Numbers array with no success in the XY Graph object.
    I even converted the DateTime string array to DateTime type using the VI called "Convert_String_to_TimeStamp.vi" with also no success as the X (Time) is just very big numbers and a datetime format.
    Please check the attached shot, it will describe the situation clearly.
    Thanks in advance
    Ayman
    Ayman Mohammad Metwally
    Automation Engineer
    Egypt - Cairo
    Solved!
    Go to Solution.
    Attachments:
    Graph.JPG ‏93 KB

    You could read the file line by line and use the scan from sting function to convert to a timestamp.
    Now is the right time to use %^<%Y-%m-%dT%H:%M:%S%3uZ>T
    If you don't hate time zones, you're not a real programmer.
    "You are what you don't automate"
    Inplaceness is synonymous with insidiousness

  • Sort String Array by Date

    I use the following code to populate a string array:
    File dirFile          = new File("C:\\somedir");
    String fileImport[]      = dirFile.list();
    This gives me a string array with a whole bunch of files in the following format:
    XXXDDMMYYHHMISS.xml
    What I need to know is what is the easiest way to sort this array based on this date format, or any date format, in the ascending order, so that when I am loading my XML files, I get the oldest one first.
    Appreciate any input.
    Sam

    Use the String name of the file (the Date part), together with a java.text.SimpleDateFormat object to parse() the String. You have to set the formatter with a pattern - these are explained fully in the Javadocs for the SimpleDateFormat class. After parsing, you will have java.util.Date objects for each of the files - you can then use these as keys in a java.util.SortedMap (the values would be the files) - the natural ordering of dates will ensure that they are ordered appropriately

  • How  to Pass String array from Java to PL/SQL  and this use in CURSOR

    hi,
    I cant understand how to pass Array String as Input Parameter to the Procedure and this array use in Cursor for where condition like where SYMPTOM in( ** Array String **).
    This array containing like (SYMPTOM ) to be returned from the java to the
    pl/sql (I am not querying the database to retrieve the information).
    I cannot find an example on this. I will give the PL/SQL block
    create or replace procedure DISEASE_DTL<*** String Array ***> as
    v_SYMPTOM number(5);
    CURSOR C1 is
    select distinct a.DISEASE_NAME from SYMPTOM_DISEASE_RD a
    where ltrim(rtrim(a.SYMPTOM)) in ('Fever','COUGH','Headache','Rash') ------- ***** Here use this array element(like n1,n2,n3,n4,n5..) ******
    group by a.DISEASE_NAME having count(a.DISEASE_NAME) > 3 ----------- ***** 3 is no of array element - 1 (i.e( n - 1))*****
    order by a.DISEASE_NAME ;
    begin
    for C1rec IN C1 loop
    select count(distinct(A.SYMPTOM)) into v_SYMPTOM from SYMPTOM_DISEASE_RD a where A.DISEASE_NAME = C1rec.DISEASE_NAME;
    insert into TEMP_DISEASE_DTLS_SYMPTOM_RD
    values (SL_ID_SEQ.nextval,
    C1rec.DISEASE_NAME,
    (4/v_SYMPTOM), --------**** 4 is no of array element (n)************
    (1-(4/v_SYMPTOM)));
    end loop;
    commit;
    end DISEASE_DTL;
    Please give the proper solution and step ..
    Thanking you,
    Asish

    I've haven't properly read through your code but here's an artificial example based on a sql collection of object types - you don't need that, you just need a type table of varchar2 rather than a type table of oracle object type:
    http://orastory.wordpress.com/2007/05/01/upscaling-your-jdbc-app/

  • Sorting a two dimensional array in descending order..

    Guy's I'm a beginning Java programmer. I've been struggling with finding documentation on sorting a two dimensional primitive array in descending order.. The following is my code which goes works, in ascending order. How do I modify it to make the list write out in descending order?
    class EmployeeTable
         public static void main(String[] args)
         int[][] hours = {
              {2, 4, 3, 4, 5, 8, 8},
              {7, 3, 4, 3, 3, 4, 4},
              {3, 3, 4, 3, 3, 2, 2},
              {9, 3, 4, 7, 3, 4, 1},
              {3, 5, 4, 3, 6, 3, 8},
              {3, 4, 4, 6, 3, 4, 4},
              {3, 7, 4, 8, 3, 8, 4},
              {6, 3, 5, 9, 2, 7, 9}};
         int [] total = new int [hours.length];
         for (int i = 0; i < hours.length ; i++){
              for (int j = 0; j < hours.length ; j++){
                   total[i] += hours[i][j];
         int[] index = new int[hours.length];
         sortIndex(total, index);
    for (int i = 0; i < hours.length; i++)
    System.out.println("Employee " + index[i] + " hours are: " +
    total[i]);
    static void sortIndex(int[] list, int[] indexList) {
    int currentMax;
    int currentMaxIndex;
    for (int i = 0; i < indexList.length; i++)
    indexList[i] = i;
    for (int i = list.length - 1; i >= 1; i--) {
    currentMax = list[i];
    currentMaxIndex = i;
    for (int j = i - 1; j >= 0; j--) {
    if (currentMax < list[j]) {
    currentMax = list[j];
    currentMaxIndex = j;
    // How do I make it go in descending order????
    if (currentMaxIndex != i) {
    list[currentMaxIndex] = list[i];
    list[i] = currentMax;
    int temp = indexList[i];
    indexList[i] = indexList[currentMaxIndex];
    indexList[currentMaxIndex] = temp;

    Bodie21 wrote:
    nclow all you wrote was
    "This looks to me like a homework assignment that you're asking us to solve for you. Your description of what it does isn't even correct. It doesn't sort a 2d array.
    You would probably elicit better help if you could demonstrate that you've done some work and have something specific that you don't understand."
    To me that sounds completely sarcastic. You didn't mention anything constructive besides that.. Hence I called you a male phalic organ, not a rear exit...Bodie21, OK, now you've got 90% of us who regularly contribute to this forum thinking your the pr&#105;ck. Is that what you wanted to do? If so, mission accomplished. Many will be looking for your name next time you ask for help. Rude enough for you?

Maybe you are looking for

  • Can you use two different iTunes accounts in Apple TV

    My wife and I have our own iTunes accounts which we use on our separate iPhones, but on the same Macbook. Can we use these separate accounts on Apple TV. Not at the same time of course. Thanks

  • Use Tax for Free of charge items

    Here is the scenario: In our Business, there is a process to give a Free item with mostly all the products sold online. In SAP, we will create regular sales order with 1 line item as TAN and other item category as TANN. The Business wants to calculat

  • Installation stuck

    I'm trying to install Bridge CC on my MacBookPro and it's been stuck at 42% for quite some time.  I've restarted my laptop and tried to install it several times and it always stops at 42%.  Any solution? Thanks, Drew

  • Embedding Font Issue

    Need help with embedding fonts.  I have the correct fonts in Pagemaker, I can export pages into pdf from PM, when I look at the PDF on my local with the fonts, they are there.  I look at the PDF on another system or mobile and the PDF does not have t

  • How do I pull up my macbook on my apple tv

    How do I pull up my macbook pro on my apple tv