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?

Similar Messages

  • Sorting a two dimensional array

    Hello!
    I have a twodimensional array that consists of 6 other arrays
    (like array[0 to 5][0 to 4]). The [4] of each sub-array is a index
    number that i'd like to use for sorting the array[0][x] to
    array[5][x] according to their array[x][4]-value. How would I do
    that?
    Thanks!

    use a custom sort function. check the sort() method of the
    array class for sample coding.

  • Sorting a two-dimensional array to check min and max random results.

    I am working on a new project to learn more advanced uses of java, and have run into some very confusing output. the program should roll 2 6 sided dice 36000 times, storing the results (how many times each of the 21 possible combinations of rolls occurred) in a 2-d array, printing that array in tabular format, then copying the values to a 1d array to sort numericallly (ascending) then print which combination of rolls occured least and most, with how many occurences for each (least and most) here is the code I have, the error will be below it.
    package d12;
    //import classes to use
    import java.util.Random;
    import java.util.Arrays;
    public class randomDice2D {
         * @param args the command line arguments
        public static void main(String[] args) {
    //bring in new Random object
            Random r = new Random();
    //declare all variables and arrays
            int[][] dieResults; dieResults = new int[6][6];
            int[] sortingResults; sortingResults=new int[37];
            int one;  int two;  int three;  int four;  int five;  int six;
            int seven;  int eight;  int nine;  int ten;  int eleven;  int twelve;
            int thirteen;  int fourteen;  int fifteen;  int sixteen;  int seventeen;
            int eighteen;  int nineteen;  int twenty;  int twentyone;
            //initialize all variables at 0
            one=0;  two=0;  three=0;  four=0;  five=0;  six=0;  seven=0;  eight=0;
            nine=0;  ten=0;  eleven=0;  twelve=0;  thirteen=0;  fourteen=0;
            fifteen=0;  sixteen=0;  seventeen=0;  eighteen=0;  nineteen=0;
            twenty=0;  twentyone=0;
    //do dice rolling and count each iteration of each possible result - 36 possible??
            for (int i = 0; i < 36000; i++)
              int roll  = (r.nextInt(6) + 1) ;
              int roll2 = (r.nextInt(6) + 1) ;
            if (roll ==1 && roll2 == 1) ++one;
            if ((roll == 1 && roll2 == 2) || (roll2 == 1 && roll == 2)) ++two;
            if ((roll == 1 && roll2 == 3) || (roll2 == 1 && roll == 3)) ++three;
            if ((roll == 1 && roll2 == 4) || (roll2 == 1 && roll == 4)) ++four;
            if ((roll == 1 && roll2 == 5) || (roll2 == 1 && roll == 5)) ++five;
            if ((roll == 1 && roll2 == 6) || (roll2 == 1 && roll == 6)) ++six;
            if (roll == 2 && roll2 == 2) ++seven;
            if ((roll == 2 && roll2 == 3) || (roll2 == 2 && roll == 3)) ++eight;
            if ((roll == 2 && roll2 == 4) || (roll2 == 2 && roll == 4)) ++nine;
            if ((roll == 2 && roll2 == 5) || (roll2 == 2 && roll == 5)) ++ten;
            if ((roll == 2 && roll2 == 6) || (roll2 == 2 && roll == 6)) ++eleven;
            if ((roll == 3 && roll2 == 3)) ++twelve;
            if ((roll == 3 && roll2 == 4) || (roll2 == 3 && roll == 4)) ++thirteen;
            if ((roll == 3 && roll2 == 5) || (roll2 == 3 && roll == 5)) ++fourteen;
            if ((roll == 3 && roll2 == 6) || (roll2 == 3 && roll == 6)) ++fifteen;
            if (roll == 4 && roll2 == 4) ++sixteen;
            if ((roll == 4 && roll2 == 5) || (roll2 == 4 && roll == 5)) ++seventeen;
            if ((roll == 4 && roll2 == 6) || (roll2 == 4 && roll == 6)) ++eighteen;
            if (roll == 5 && roll2 == 5) ++nineteen;
            if ((roll == 5 && roll2 == 6) || (roll2 == 5 && roll == 6)) ++twenty;
            if (roll == 6 && roll2 == 6) ++twentyone;
            //assign results to array
            dieResults[0][0]=one;
            dieResults[1][0]=two; dieResults[0][1]=two;
            dieResults[2][0]=three;dieResults[0][2]=three;
            dieResults[3][0]=four;dieResults[0][3]=four;
            dieResults[4][0]=five;dieResults[0][4]=five;
            dieResults[5][0]=six;dieResults[0][5]=six;
            dieResults[1][1]=seven;
            dieResults[2][1]=eight;dieResults[1][2]=eight;dieResults[3][1]=nine;
            dieResults[1][3]=nine;dieResults[4][1]=ten;dieResults[1][4]=ten;
            dieResults[5][1]=eleven;dieResults[1][5]=eleven;
            dieResults[2][2]=twelve;
            dieResults[3][2]=thirteen;dieResults[2][3]=thirteen;
            dieResults[4][2]=fourteen;dieResults[2][4]=fourteen;
            dieResults[5][2]=fifteen;dieResults[2][5]=fifteen;
            dieResults[3][3]=sixteen;
            dieResults[4][3]=seventeen;dieResults[3][4]=seventeen;
            dieResults[5][3]=eighteen;dieResults[3][5]=eighteen;
            dieResults[4][4]=nineteen;
            dieResults[5][4]=twenty;dieResults[4][5]=twenty;
            dieResults[5][5]=twentyone;
            //print results
            for (int j=0; j<dieResults.length; j++){
                System.out.print("\n");
                for (int k=0; k<dieResults.length; k++){
                System.out.print("|"+dieResults[j][k]+"| ");
            // Verify program accuracy and ensure total reported results add up to 36000
    System.out.println("\nValidate: 1's; "+dieResults[0][0]+" 1 & 2; "+dieResults[1][0]+
            dieResults[0][1]+" 4's; "+dieResults[2][0]+dieResults[0][2]+" 5's; "
            +dieResults[3][0]+dieResults[0][3]+" 6's; "+dieResults[4][0]+dieResults[0][4]
            +" 7's; "+dieResults[5][0]+dieResults[0][5]);
    System.out.println("All total rolls add up to " + (dieResults[0][0] + dieResults[0][1] +
             dieResults[0][2] + dieResults[0][3] + dieResults[0][4] + dieResults[0][5]));
    //check lowest/highest numbers entered to verify results are reasonable
    //sort results to obtain lowest and highest number of rolls
        for (int l=0; l<sortingResults.length;l++){
         for (int m=0; m<sortingResults.length;m++){
            sortingResults[l]=dieResults[l][m];
    Arrays.sort(sortingResults);
    //determine and print what roll occurred the least
        if (sortingResults[0] == two)
            System.out.println("The lowest number of rolls for a single result is "
                    + "2's with " + sortingResults[0]);
        if (sortingResults[0] == three)
            System.out.println("The lowest number of rolls for a single result is "
                    + "3's with " + sortingResults[0]);
        if (sortingResults[0] == four)
            System.out.println("The lowest number of rolls for a single result is "
                    + "4's with " + sortingResults[0]);
        if (sortingResults[0] == five)
            System.out.println("The lowest number of rolls for a single result is "
                    + "5's with " + sortingResults[0]);
        if (sortingResults[0] == six)
            System.out.println("The lowest number of rolls for a single result is "
                    + "6's with " + sortingResults[0]);
        if (sortingResults[0] == seven)
            System.out.println("The lowest number of rolls for a single result is "
                    + "7's with " + sortingResults[0]);
        if (sortingResults[0] == eight)
            System.out.println("The lowest number of rolls for a single result is "
                    + "8's with " + sortingResults[0]);
        if (sortingResults[0] == nine)
            System.out.println("The lowest number of rolls for a single result is "
                    + "9's with " + sortingResults[0]);
        if (sortingResults[0] == ten)
            System.out.println("The lowest number of rolls for a single result is "
                    + "10's with " + sortingResults[0]);
        if (sortingResults[0] == eleven)
            System.out.println("The lowest number of rolls for a single result is "
                    + "11's with " + sortingResults[0]);
        if (sortingResults[0] == twelve)
            System.out.println("The lowest number of rolls for a single result is "
                    + "12's with " + sortingResults[0]);
    //determine and print what roll occurred the most
        if (dieResults[5][5] == two)
            System.out.println("The highest number of rolls for a single result is "
                    + "2's with " + dieResults[10]);
        if (dieResults[5][5] == three)
            System.out.println("The highest number of rolls for a single result is "
                    + "3's with " + dieResults[10]);
        if (dieResults[5][5] == four)
            System.out.println("The highest number of rolls for a single result is "
                    + "4's with " + dieResults[10]);
        if (dieResults[5][5] == five)
            System.out.println("The highest number of rolls for a single result is "
                    + "5's with " + dieResults[10]);
        if (dieResults[5][5] == six)
            System.out.println("The highest number of rolls for a single result is "
                    + "6's with " + dieResults[10]);
        if (dieResults[5][5] == seven)
            System.out.println("The highest number of rolls for a single result is "
                    + "7's with " + dieResults[10]);
        if (dieResults[5][5] == eight)
            System.out.println("The highest number of rolls for a single result is "
                    + "8's with " + dieResults[10]);
        if (dieResults[5][5] == nine)
            System.out.println("The highest number of rolls for a single result is "
                    + "9's with " + dieResults[10]);
        if (dieResults[5][5] == ten)
            System.out.println("The lohighestwest number of rolls for a single result is "
                    + "10's with " + dieResults[10]);
        if (dieResults[5][5] == eleven)
            System.out.println("The highest number of rolls for a single result is "
                    + "11's with " + dieResults[10]);
        if (dieResults[5][5] == twelve)
            System.out.println("The highest number of rolls for a single result is "
                    + "12's with " + dieResults[10]);
    }the output I got was this:
    run:
    |988| |2038| |1933| |2008| |2095| |2002|
    Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 6
    |2038| |965| |1973| |1982| |1985| |2028|
    |1933| |1973| |1034| |1952| |1928| |2055|
    |2008| |1982| |1952| |1010| |1981| |2023|
    |2095| |1985| |1928| |1981| |1041| |1996|
    |2002| |2028| |2055| |2023| |1996| |983| Validate: 1's; 988 1 & 2; 20382038 4's; 19331933 5's; 20082008 6's; 20952095 7's; 20022002
    All total rolls add up to 11064
            at d12.randomDice2D.main(randomDice2D.java:101)
    Java Result: 1
    BUILD SUCCESSFUL (total time: 0 seconds)I can see from the validate line in output that i need to start that line with a \n and change the formula of that println from
    +dieResults[x][y]+dieResults[y][x]+
    to
    +(dieResults[x][y]+dieResults[y][x])+
    I am also aware i have to finish listing all the elements of the array to add to the all total rolls line, but that I can add as I wait for an answer to the errors I don't see the solutions to. The last thing I need help with is how to print those results in a 2-d table format instead of one number per line. Should I change the pair of loops here:
    for (int l=0; l<sortingResults.length;l++){
         for (int m=0; m<sortingResults.length;m++){
            sortingResults[l]=dieResults[l][m];
            }    }to a single loop repeated till the end like this?
    for (int l=0; l<6; l++){
    sortingResults[l]=dieResults[l][0];}
    for (int m=0; m<5; m++){
    sortingResults[(m+6)]=dieResults[m][1];}
    for (int n=0; n<4; n++){
    sortingResults[(n+11)]=dieResults[n][1];}or just take 21 lines (or 36 if i track all results instead of all unique) to declare each element like:
    sortingResults[a]=dieResults[x][y];
    Edited by: Geode on Oct 20, 2010 12:38 AM

    Ok, I have done a lot and thought I had worked out all of the problems. Netbeans had no problems compiling it or running it, and the output was exactly what I expected it to be. Then I decided that the println starting "Validate:" was unneccessary since I printed the table right before it, so I deleted it. Noww Netbeans is telling me it compiles with errors every time i run it, even though it doesn't flag any line as having an error and it still executes exactly as I expect it to. Also, I was not able to find a way to make the three big sets of if's into loops. Any suggestions or ideas on how they could be looped would be most welcome. Also, any ideas on why Netbeans is saying it compiles with errors when it does not give any. I'll give the code and then the output again.
    package d12;
    //import classes to use
    import java.util.Random;
    import java.util.Arrays;
    public class randomDice2D {
         * @param args the command line arguments
        public static void main(String[] args) {
    //bring in new Random object
            Random r = new Random();
    //declare all variables and arrays
            int[][] dieResults; dieResults = new int[6][6];
            int[] sortingResults; sortingResults=new int[36];
            int one; int two; int three; int four; int five; int six; int seven;
            int eight; int nine; int ten; int eleven; int twelve; int thirteen;
            int fourteen; int fifteen; int sixteen; int seventeen; int eighteen;
            int nineteen; int twenty; int twentyone; int twentytwo; int twentythree;
            int twentyfour; int twentyfive; int twentysix; int twentyseven;
            int twentyeight; int twentynine; int thirty; int thirtyone; int thirtytwo;
            int thirtythree; int thirtyfour; int thirtyfive; int thirtysix;
            //initialize all variables at 0
            one=0;two=0;three=0;four=0;five=0;six=0;seven=0;eight=0;nine=0;ten=0;
            eleven=0;twelve=0;thirteen=0;fourteen=0;fifteen=0;sixteen=0;seventeen=0;
            eighteen=0;nineteen=0;twenty=0;twentyone=0;twentytwo=0;twentythree=0;
            twentyfour=0;twentyfive=0;twentysix=0;twentyseven=0;twentyeight=0;
            twentynine=0;thirty=0;thirtyone=0;thirtytwo=0;thirtythree=0;thirtyfour=0;
            thirtyfive=0;thirtysix=0;
    //do dice rolling and count each iteration of each possible result - 36 possible??
            for (int i = 0; i < 36000; i++)
              int roll  = (r.nextInt(6) + 1) ;
              int roll2 = (r.nextInt(6) + 1) ;
            if (roll == 1 && roll2 == 1) ++one;
            if (roll == 1 && roll2 == 2) ++two;
            if (roll == 1 && roll2 == 3) ++three;
            if (roll == 1 && roll2 == 4) ++four;
            if (roll == 1 && roll2 == 5) ++five;
            if (roll == 1 && roll2 == 6) ++six;
            if (roll == 2 && roll2 == 1) ++seven;
            if (roll == 2 && roll2 == 2) ++eight;
            if (roll == 2 && roll2 == 3) ++nine;
            if (roll == 2 && roll2 == 4) ++ten;
            if (roll == 2 && roll2 == 5) ++eleven;
            if (roll == 2 && roll2 == 6) ++twelve;
            if (roll == 3 && roll2 == 1) ++thirteen;
            if (roll == 3 && roll2 == 2) ++fourteen;
            if (roll == 3 && roll2 == 3) ++fifteen;
            if (roll == 3 && roll2 == 4) ++sixteen;
            if (roll == 3 && roll2 == 5) ++seventeen;
            if (roll == 3 && roll2 == 6) ++eighteen;
            if (roll == 4 && roll2 == 1) ++nineteen;
            if (roll == 4 && roll2 == 2) ++twenty;
            if (roll == 4 && roll2 == 3) ++twentyone;
            if (roll == 4 && roll2 == 4) ++twentytwo;
            if (roll == 4 && roll2 == 5) ++twentythree;
            if (roll == 4 && roll2 == 6) ++twentyfour;
            if (roll == 5 && roll2 == 1) ++twentyfive;
            if (roll == 5 && roll2 == 2) ++twentysix;
            if (roll == 5 && roll2 == 3) ++twentyseven;
            if (roll == 5 && roll2 == 4) ++twentyeight;
            if (roll == 5 && roll2 == 5) ++twentynine;
            if (roll == 5 && roll2 == 6) ++thirty;
            if (roll == 6 && roll2 == 1) ++thirtyone;
            if (roll == 6 && roll2 == 2) ++thirtytwo;
            if (roll == 6 && roll2 == 3) ++thirtythree;
            if (roll == 6 && roll2 == 4) ++thirtyfour;
            if (roll == 6 && roll2 == 5) ++thirtyfive;
            if (roll == 6 && roll2 == 6) ++thirtysix;
            //assign results to array
            dieResults[0][0]=one;dieResults[1][0]=seven; dieResults[0][1]=two;
            dieResults[2][0]=thirteen;dieResults[0][2]=three;dieResults[3][0]=nineteen;
            dieResults[0][3]=four;dieResults[4][0]=twentyfive;dieResults[0][4]=five;
            dieResults[5][0]=thirtyone;dieResults[0][5]=six;dieResults[1][1]=eight;
            dieResults[2][1]=fourteen;dieResults[1][2]=nine;dieResults[3][1]=twenty;
            dieResults[1][3]=ten;dieResults[4][1]=twentysix;dieResults[1][4]=eleven;
            dieResults[5][1]=thirtytwo;dieResults[1][5]=twelve;dieResults[2][2]=fifteen;
            dieResults[3][2]=twentyone;dieResults[2][3]=sixteen;dieResults[4][2]=twentyseven;
            dieResults[2][4]=seventeen;dieResults[5][2]=thirtythree;dieResults[2][5]=eighteen;
            dieResults[3][3]=twentytwo;dieResults[4][3]=twentyeight;dieResults[3][4]=twentythree;
            dieResults[5][3]=thirtyfour;dieResults[3][5]=twentyfour;dieResults[4][4]=twentynine;
            dieResults[5][4]=thirtyfive;dieResults[4][5]=thirty;dieResults[5][5]=thirtysix;
            //print results
            System.out.println("     1      2      3      4     5      6");
            for (int j=0; j<dieResults.length; j++){
                System.out.print("\n"+(j+1)+" -");
                for (int k=0; k<dieResults.length; k++){
                System.out.print("|"+dieResults[j][k]+"| ");
            // Verify program accuracy to ensure total results add up to 36000
    System.out.println("\nAll total rolls add up to "+(dieResults[0][0]+dieResults[0][1]+
             dieResults[0][2]+dieResults[0][3]+dieResults[0][4]+dieResults[0][5]+
             dieResults[1][0]+dieResults[1][1]+dieResults[1][2]+dieResults[1][3]+
             dieResults[1][4]+dieResults[1][5]+dieResults[2][0]+dieResults[2][1]+
             dieResults[2][2]+dieResults[2][3]+dieResults[2][4]+dieResults[2][5]+
             dieResults[3][0]+dieResults[3][1]+dieResults[3][2]+dieResults[3][3]+
             dieResults[3][4]+dieResults[3][5]+dieResults[4][0]+dieResults[4][1]+
             dieResults[4][2]+dieResults[4][3]+dieResults[4][4]+dieResults[4][5]+
             dieResults[5][0]+dieResults[5][1]+dieResults[5][2]+dieResults[5][3]+
             dieResults[5][4]+dieResults[5][5]));
    //check lowest/highest numbers entered to verify results are reasonable
    //sort results to obtain lowest and highest number of rolls 
    int z;z=0;
    while (z < 36){
    for (int l=0; l<6;l++){
         for (int m=0; m<6;m++){
            sortingResults[z]=dieResults[l][m];++z;
    Arrays.sort(sortingResults);
    //determine and print what roll occurred the least
        if (sortingResults[0] == one)
            System.out.println("The lowest number of rolls for a single result is "
                    + "1's with " + sortingResults[0]);
        if (sortingResults[0] == two)
            System.out.println("The lowest number of rolls for a single result is "
                    + "1 & 2 with " + sortingResults[0]);
        if (sortingResults[0] == three)
            System.out.println("The lowest number of rolls for a single result is "
                    + "1 & 3 with " + sortingResults[0]);
        if (sortingResults[0] == four)
            System.out.println("The lowest number of rolls for a single result is "
                    + "1 & 4 with " + sortingResults[0]);
        if (sortingResults[0] == five)
            System.out.println("The lowest number of rolls for a single result is "
                    + "1 & 5 with " + sortingResults[0]);
        if (sortingResults[0] == six)
            System.out.println("The lowest number of rolls for a single result is "
                    + "1 & 6 with " + sortingResults[0]);
        if (sortingResults[0] == seven)
            System.out.println("The lowest number of rolls for a single result is "
                    + "2 & 1 with " + sortingResults[0]);
        if (sortingResults[0] == eight)
            System.out.println("The lowest number of rolls for a single result is "
                    + "2 & 2 with " + sortingResults[0]);
        if (sortingResults[0] == nine)
            System.out.println("The lowest number of rolls for a single result is "
                    + "2 & 3 with " + sortingResults[0]);
        if (sortingResults[0] == ten)
            System.out.println("The lowest number of rolls for a single result is "
                    + "2 & 4 with " + sortingResults[0]);
        if (sortingResults[0] == eleven)
            System.out.println("The lowest number of rolls for a single result is "
                    + "2 & 5 with " + sortingResults[0]);
        if (sortingResults[0] == twelve)
            System.out.println("The lowest number of rolls for a single result is "
                    + "2 & 6 with " + sortingResults[0]);
        if (sortingResults[0] == thirteen)
            System.out.println("The lowest number of rolls for a single result is "
                    + "3 & 1 with " + sortingResults[0]);
        if (sortingResults[0] == fourteen)
            System.out.println("The lowest number of rolls for a single result is "
                    + "3 & 2 with " + sortingResults[0]);
        if (sortingResults[0] == fifteen)
            System.out.println("The lowest number of rolls for a single result is "
                    + "3 & 3 with " + sortingResults[0]);
        if (sortingResults[0] == sixteen)
            System.out.println("The lowest number of rolls for a single result is "
                    + "3 & 4 with " + sortingResults[0]);
        if (sortingResults[0] == seventeen)
            System.out.println("The lowest number of rolls for a single result is "
                    + "3 & 5 with " + sortingResults[0]);
        if (sortingResults[0] == eighteen)
            System.out.println("The lowest number of rolls for a single result is "
                    + "3 & 6 with " + sortingResults[0]);
        if (sortingResults[0] == nineteen)
            System.out.println("The lowest number of rolls for a single result is "
                    + "4 & 1 with " + sortingResults[0]);
        if (sortingResults[0] == twenty)
            System.out.println("The lowest number of rolls for a single result is "
                    + "4 & 2 with " + sortingResults[0]);
        if (sortingResults[0] == twentyone)
            System.out.println("The lowest number of rolls for a single result is "
                    + "4 & 3 with " + sortingResults[0]);
        if (sortingResults[0] == twentytwo)
            System.out.println("The lowest number of rolls for a single result is "
                    + "4 & 4 with " + sortingResults[0]);
        if (sortingResults[0] == twentythree)
            System.out.println("The lowest number of rolls for a single result is "
                    + "4 & 5 with " + sortingResults[0]);
        if (sortingResults[0] == twentyfour)
            System.out.println("The lowest number of rolls for a single result is "
                    + "4 & 6 with " + sortingResults[0]);
        if (sortingResults[0] == twentyfive)
            System.out.println("The lowest number of rolls for a single result is "
                    + "5 & 1 with " + sortingResults[0]);
        if (sortingResults[0] == twentysix)
            System.out.println("The lowest number of rolls for a single result is "
                    + "5 & 2 with " + sortingResults[0]);
        if (sortingResults[0] == twentyseven)
            System.out.println("The lowest number of rolls for a single result is "
                    + "5 & 3 with " + sortingResults[0]);
        if (sortingResults[0] == twentyeight)
            System.out.println("The lowest number of rolls for a single result is "
                    + "5 & 4 with " + sortingResults[0]);
        if (sortingResults[0] == twentynine)
            System.out.println("The lowest number of rolls for a single result is "
                    + "5 & 5 with " + sortingResults[0]);
        if (sortingResults[0] == thirty)
            System.out.println("The lowest number of rolls for a single result is "
                    + "5 & 6 with " + sortingResults[0]);
        if (sortingResults[0] == thirtyone)
            System.out.println("The lowest number of rolls for a single result is "
                    + "6 & 1 with " + sortingResults[0]);
        if (sortingResults[0] == thirtytwo)
            System.out.println("The lowest number of rolls for a single result is "
                    + "6 & 2 with " + sortingResults[0]);
        if (sortingResults[0] == thirtythree)
            System.out.println("The lowest number of rolls for a single result is "
                    + "6 & 3 with " + sortingResults[0]);
        if (sortingResults[0] == thirtyfour)
            System.out.println("The lowest number of rolls for a single result is "
                    + "6 & 4 with " + sortingResults[0]);
        if (sortingResults[0] == thirtyfive)
            System.out.println("The lowest number of rolls for a single result is "
                    + "6 & 5 with " + sortingResults[0]);
        if (sortingResults[0] == thirtysix)
            System.out.println("The lowest number of rolls for a single result is "
                    + "6 & 6 with " + sortingResults[0]);
    //determine and print what roll occurred the most
        if (sortingResults[35] == one)
            System.out.println("The highest number of rolls for a single result is "
                    + "1's with " + sortingResults[35]);
        if (sortingResults[35] == two)
            System.out.println("The highest number of rolls for a single result is "
                    + "1 & 2 with " + sortingResults[35]);
        if (sortingResults[35] == three)
            System.out.println("The highest number of rolls for a single result is "
                    + "1 & 3 with " + sortingResults[35]);
        if (sortingResults[35] == four)
            System.out.println("The highest number of rolls for a single result is "
                    + "1 & 4 with " + sortingResults[35]);
        if (sortingResults[35] == five)
            System.out.println("The highest number of rolls for a single result is "
                    + "1 & 5 with " + sortingResults[35]);
        if (sortingResults[35] == six)
            System.out.println("The highest number of rolls for a single result is "
                    + "1 & 6 with " + sortingResults[35]);
        if (sortingResults[35] == seven)
            System.out.println("The highest number of rolls for a single result is "
                    + "2 & 1 with " + sortingResults[35]);
        if (sortingResults[35] == eight)
            System.out.println("The highest number of rolls for a single result is "
                    + "2 & 2 with " + sortingResults[35]);
        if (sortingResults[35] == nine)
            System.out.println("The highest number of rolls for a single result is "
                    + "2 & 3 with " + sortingResults[35]);
        if (sortingResults[35] == ten)
            System.out.println("The highest number of rolls for a single result is "
                    + "2 & 4 with " + sortingResults[35]);
        if (sortingResults[35] == eleven)
            System.out.println("The highest number of rolls for a single result is "
                    + "2 & 5 with " + sortingResults[35]);
        if (sortingResults[35] == twelve)
            System.out.println("The highest number of rolls for a single result is "
                    + "2 & 6 with " + sortingResults[35]);
        if (sortingResults[35] == thirteen)
            System.out.println("The highest number of rolls for a single result is "
                    + "3 & 1 with " + sortingResults[35]);
        if (sortingResults[35] == fourteen)
            System.out.println("The highest number of rolls for a single result is "
                    + "3 & 2 with " + sortingResults[35]);
        if (sortingResults[35] == fifteen)
            System.out.println("The highest number of rolls for a single result is "
                    + "3 & 3 with " + sortingResults[35]);
        if (sortingResults[35] == sixteen)
            System.out.println("The highest number of rolls for a single result is "
                    + "3 & 4 with " + sortingResults[35]);
        if (sortingResults[35] == seventeen)
            System.out.println("The highest number of rolls for a single result is "
                    + "3 & 5 with " + sortingResults[35]);
        if (sortingResults[35] == eighteen)
            System.out.println("The highest number of rolls for a single result is "
                    + "3 & 6 with " + sortingResults[35]);
        if (sortingResults[35] == nineteen)
            System.out.println("The highest number of rolls for a single result is "
                    + "4 & 1 with " + sortingResults[35]);
        if (sortingResults[35] == twenty)
            System.out.println("The highest number of rolls for a single result is "
                    + "4 & 2 with " + sortingResults[35]);
        if (sortingResults[35] == twentyone)
            System.out.println("The highest number of rolls for a single result is "
                    + "4 & 3 with " + sortingResults[35]);
        if (sortingResults[35] == twentytwo)
            System.out.println("The highest number of rolls for a single result is "
                    + "4 & 4 with " + sortingResults[35]);
        if (sortingResults[35] == twentythree)
            System.out.println("The highest number of rolls for a single result is "
                    + "4 & 5 with " + sortingResults[35]);
        if (sortingResults[35] == twentyfour)
            System.out.println("The highest number of rolls for a single result is "
                    + "4 & 6 with " + sortingResults[35]);
        if (sortingResults[35] == twentyfive)
            System.out.println("The highest number of rolls for a single result is "
                    + "5 & 1 with " + sortingResults[35]);
        if (sortingResults[35] == twentysix)
            System.out.println("The highest number of rolls for a single result is "
                    + "5 & 2 with " + sortingResults[35]);
        if (sortingResults[35] == twentyseven)
            System.out.println("The highest number of rolls for a single result is "
                    + "5 & 3 with " + sortingResults[35]);
        if (sortingResults[35] == twentyeight)
            System.out.println("The highest number of rolls for a single result is "
                    + "5 & 4 with " + sortingResults[35]);
        if (sortingResults[35] == twentynine)
            System.out.println("The highest number of rolls for a single result is "
                    + "5 & 5 with " + sortingResults[35]);
        if (sortingResults[35] == thirty)
            System.out.println("The highest number of rolls for a single result is "
                    + "5 & 6 with " + sortingResults[35]);
        if (sortingResults[35] == thirtyone)
            System.out.println("The highest number of rolls for a single result is "
                    + "6 & 1 with " + sortingResults[35]);
        if (sortingResults[35] == thirtytwo)
            System.out.println("The highest number of rolls for a single result is "
                    + "6 & 2 with " + sortingResults[35]);
        if (sortingResults[35] == thirtythree)
            System.out.println("The highest number of rolls for a single result is "
                    + "6 & 3 with " + sortingResults[35]);
        if (sortingResults[35] == thirtyfour)
            System.out.println("The highest number of rolls for a single result is "
                    + "6 & 4 with " + sortingResults[35]);
        if (sortingResults[35] == thirtyfive)
            System.out.println("The highest number of rolls for a single result is "
                    + "6 & 5 with " + sortingResults[35]);
        if (sortingResults[35] == thirtysix)
            System.out.println("The highest number of rolls for a single result is "
                    + "6 & 6 with " + sortingResults[35]);
    }and here is the output (after clicking 'Run Anyways' on the project compiled with errors message from Netbeans)
    run:
         1      2      3      4     5      6
    1 -|995| |1014| |1076| |976| |1015| |1000|
    2 -|971| |982| |993| |1067| |983| |1011|
    3 -|990| |951| |1019| |968| |1011| |1023|
    4 -|999| |931| |1009| |987| |1020| |1022|
    5 -|969| |954| |997| |970| |1016| |1028|
    6 -|955| |1014| |996| |996| |1075| |1017|
    All total rolls add up to 36000
    The lowest number of rolls for a single result is 4 & 2 with 931
    The highest number of rolls for a single result is 1 & 3 with 1076
    BUILD SUCCESSFUL (total time: 13 seconds)

  • How to get number of rows and columns in a two dimensional array ?

    Hello,
    What would be the simplest way to get number of rows and columns in a two dimensional array represented as integers ?
    I'm looking for another solution as For...Each loop in case of large arrays.
    Regards,
    Petri

    Hi Petri,
    See a attached txt file for obtaining two arrays with upper and lower index values
    Regards
    Ray
    Regards
    Ray Farmer
    Attachments:
    Get2DArrayIndex.txt ‏2 KB

  • How to copy data in text file into two-dimensional arrays?

    Greeting. Can somebody teach me how to copy the input file into two-dimensional arrays? I'm stuck in making a matrix with number ROWS and COLUMNS according to the data in "input.txt"
    import java.io.*;
    import java.util.*;
    public class array
        public static void main (String[] args) throws FileNotFoundException
        { Scanner sc = new Scanner (new FileReader("input.txt"));
            PrintWriter outfile = new PrintWriter("output.txt");
        int[][]matrix = new int[ROWS][COLUMNS];
    }my input.txt :
    a,b,c
    2,2,1
    1,1,1
    2,2,1
    3,3,1
    4,4,1
    5,5,1
    1,6,2
    2,7,2
    3,8,2
    4,9,2
    5,10,2

    import java.io.*;
    import java.util.*;
    public class array {
        public static void main(String[] args) throws IOException {
            FileInputStream in = null;
            FileOutputStream out = null;
    try {
        in = new FileInputStream("input.txt");
        BufferedReader reader = new BufferedReader(new InputStreamReader(in));
        String line = null;
        while ((line = reader.readLine()) != null) {
            String split[]=line.split(",");
    catch (IOException x) {
        System.err.println(x);
    } finally {
        if (in != null) in.close();
    }}}What after this?

  • How to use two dimensional array in custom.pll

    HI
    How to use two dimensional arrays in custom.pll
    I tried by the following way .
    type ship_array is table of number index by binary_integer;
    type vc_array is table of ship_array index by binary_integer;
    But I am getting the error as that
    A plsql table may not contain a table or a record with composite fields.
    Please tell me the way how to use them

    which forms version are you using? two dimensional arrays are available in >= 9i if memory serves.
    regards

  • Variable number of two dimensional arrays into one big array

    I have a variable number of two dimensional arrays.
    The first dimension is variable, the second dimension is always 7.
    i.e.:
    Object[][] array0 = {
    {"tim", "sanchez", 34, 175.5, "bla", "blub", "[email protected]"},
    {"alice", "smith", 42, 160.0, "la", "bub", "[email protected]"},
    Object[][] array1 = {
    {"john", "sdfs", 34, 15.5, "a", "bl", "[email protected]"},
    {"joe", "smith", 42, 16.0, "a", "bub", "[email protected]"},
    Object[][] arrayi = ...I'm generating these arrays with a for-loop:
         for (int i = 0; i < filter.length; i++) {
              MyClass c = new MyClass(filter);
              //data = c.getData();
    Where "filter" is another array which is filled with information that tells "MyClass" how to fill the arrays.
    "getData()" gives back one of the i number of arrays.
    Now I just need to have everything in one big two dimensional array.
    i.e.:Object[][] arrayComplete = {
    {"tim", "sanchez", 34, 175.5, "bla", "blub", "[email protected]"},
    {"alice", "smith", 42, 160.0, "la", "bub", "[email protected]"},
    {"john", "sdfs", 34, 15.5, "a", "bl", "[email protected]"},
    {"joe", "smith", 42, 16.0, "a", "bub", "[email protected]"},
    Any idea on how to accomplish this? It's blowing my mind right now.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

    Just brainstorming here:
    Why not put your actual data in a class and store that in a LinkedList (so you know the total number of elements for your multi-dimensional array). Then initalize your multi-dimensional array and populate it? Haven't tested the following, but thinking something along the lines of
    public class MyData {
         //data here
         public Object[] toArray() {
              //something similar to this
              return new Object[] = {"tim", "sanchez", 34, 175.5, "bla", "blub", "[email protected]"};
    LinkedList<MyData> data = new LinkedList<MyData>();
    data.add(mydata1);
    //however many times you need
    Object[][] arrayComplete = new Object[data.size()][7];
    for(int i = 0; i < data.size(); i++) {
         arrayComplete[i] = data.removeFirst().toArray();
    }Another option for knowing how many rows you would need might be using something like:
    int rows = 0;
    rows += array1.length;
    rows += array2.length;
    //etc...But is not entirely useful if you don't know how many variable arrays you have (although reflections might help if the name of the array variable is incremented systematically, someone told me earlier to avoid reflections since it could make debugging a LOT more difficult).
    Edited by: bogdana on Apr 1, 2010 10:38 AM

  • Problem returning a two-dimensional array in web service

    Hello. I'm having problems returning a two dimensional array in my web service. The service returns a MyClass[][] correctly, but the client receives a different one.
    I've done a test that returns a MyClass[1][1] an the client shows a MyClass[1][20]. All the MyClass objects returned in the array are the same and all it's fields are null. There's even an element of the array containing null instead of the object. As I say, the service creates the array ok, but the client gets other thing.
    I have other methods returning one-dimensional arrays MyClass[] and I have no problem.
    My system:
    WindowsXP
    Tomcat 5.5 (Axis 1.3?)
    JDK 1.5
    Eclipse 3.3
    My wsdl is generated with eclipse, although I've had to update my wsdd manually.
    Any Ideas?
    Thanks.

    Does it have to be stored in an array?
    Because you could use the java.awt.Point class, and a
    java.util.Set to create random points until you have
    the correct number of unique points.Of course it is no must to store it in an array. it was just my first thought of approaching the problem. I will try the Point.class. Thanks for that hint.

  • Creating one and two Dimensional array

    Hi guys my problem is as follows
    (1)I want to create a two dimensional array of 10 rows and 20 columns
    (2)Populate the array with random integers
    (3)convert the two dimensinal array into one dimensional array int[]nums
    (4)print the content of one and two dimensional arrays to the screen

    You don't learn much about coding if you don't write any code. Without seeing the code that was written it's very difficult to assist a person, since your solution may not be anywhere close to their solution. If the poster just wants the code to hand in or use as is then there is no learning happening.
    So, step 1 - post your code, step 1a - ask a clear question.
    Just my opinions
    Lee

  • Count the number of values in a two dimensional array

    i am trying to figure out how to count the number of values in a two dimensional array.
    numScores = student[i][j].length;This doesn't work, i am trying to find a way of counting the columns

    Object[][] o;
    int tot = 0;
    for(int x = 0 ; x < o.length ; x++)
       tot += o[x].length;
    }If it's not a jagged array, however, this would be easier:
    int tot = o.length * o[0].length;

  • Need to sort results in a report in descending order

    Hi,
    We have OIM 10g and we need to sort the report on date in descending order. I tried this code but still the column is not getting sorted.
    Evertime I generate the report, the results are sorted only in ascending order.
    Here the stored procedure code for sorting:
    strOrderByClause := 'abc.date';
    IF strsortorder_in = 'DESC' THEN
    intSortDirection_in := 0;
    ELSE
    intSortDirection_in := 1;
    END IF;
    Please let me know if you have faced similar issue.
    Thanks,
    Kalpana.

    Hi,
    If Oracle can give you back the right sort order without any custom sorting,
    that means you should be able to get the same results in WebI.
    If the object that you pull from the universe is the wrong type (like numeric but you want it alphanumeric),
    then you can either request you designer to give you an object with the right data type,
    or you can change it by creating a report variable using
    FormatNumber([original object],"0")
    this will format the number to a number without leading zeroes, thousand separators or decimal point.
    Now you can use the object as if it came from the universe.
    So you can also use it on the x-axis of a chart.
    Btw. you can also do a custom sort on the x-axis(as long as it is an object or variable, not a formula)
    alternative, if you define a custom sort in a table block, you can state it should be used througout the document.
    (so also in the charts.
    Hope this helps,
    Marianne

  • Set number of elements in a two dimensional array

    Hi,
    Does anyone know how to set the number of elements in a two dimensional array directly in teststand.
    To set a one dimsional array is simple:
    SetNumElements( locals.somearray,4)
    Is there a method to do this for a two dimensional array?
    Sean

    From the help file (TestStand 4.2.0):
    PropertyObject.SetNumElements
    SetNumElements Method
    Syntax
    PropertyObject.SetNumElements ( numElements, options = 0)
    Purpose
    Sets the number of elements of a single dimensional array.
    Remarks
    This method is only valid for single dimensional arrays. The elements in the array retain their values. Use the PropertyObjectType.ArrayDimensions property to set the number of elements in each dimension of a multi-dimensional array.
    Parameters
    numElements As Long
    [In] New number of elements for the array.
    options As Long
    [In] Pass 0 to specify the default behavior, or pass one or more PropertyOptions constants. Use the bitwise-OR operator to specify multiple options.
    This parameter has a default value of 0.
    So you could use, for example: Locals.MultidimensionalArray.Type.ArrayDimensions.SetBounds({1,0},{3,4}) to set an array to have three dimensions (1,2,3), each with five elements (0,1,2,3,4).

  • Two dimensional array in JSP with struts

    Is it possible to use two dimensional array in an web application
    based on struts. I am using JSP and to get data from two dimensional
    array im using
    property = "array[0][0]";I read on the internet that bean utils does not support two dimensional array?
    I have a table like spreadsheet with 30 rows and 20 columns and i was
    planning to use two dimensional array? is there any other way to get
    this stuff done easily?
    any ideas welcome.

    HI ,
    i have the same problem you had
    did you get any solution for this?
    if so you can help me out

  • Creating a Two Dimensional Array in Xcode and populating it with a values f

    Whats the easiest way to declare a two dimensional array in Xcode. I am reading an matrix of numbers from a text file from a website and want to take the data and place it into a 3x3 matrix.
    Once I read the URL into a string, I create an NSArray and use the componentsSeparatedByString method to strip of the carriage return line feed and create each individual row. I then get the count of the number of lines in the new array to get the individual values at each row. This will give mw an array with a string of characters, not a row of three individual values. I just need to be able to take these values and create a two dimensional array.

    I'm afraid you are in the wrong place. Look here for the last two forums on programming. However, XCode support is mostly found at developer.apple.com. You can access their forums by registering. Registration is free.

  • How can I use two dimensional array ?

    Could some one show me how to use two dimentional array ?
    I am know how to right a single ...but not two dimentional....please help,
    Thanks,
    Flower
    public class Exam5
    public static void main(String[] args)
    int[][] numbers =
         {     {1,2,3,4,5,6,7,8,9,10},
    {1,2,3,4,5,6,7,8,9,10} };
    for(int i = 1; i < 11; ++i)
    System.out.println(i + "\t" + i * 2 + "\t" + i * 3 + "\t" + i * 4 + "\t" + i * 5 +
    "\t" + i * 6 + "\t" + i * 7 + "\t" + i * 8 + "\t" + i * 9 + "\t" + i * 10);
    Display #
    1     2     3     4     5     6     7     8     9     10
    2     4     6     8     10     12     14     16     18     20
    3     6     9     12     15     18     21     24     27     30
    4     8     12     16     20     24     28     32     36     40
    5     10     15     20     25     30     35     40     45     50
    6     12     18     24     30     36     42     48     54     60
    7     14     21     28     35     42     49     56     63     70
    8     16     24     32     40     48     56     64     72     80
    9     18     27     36     45     54     63     72     81     90
    10     20     30     40     50     60     70     80     90     100

    First, try not to ask someone to do your homework for you and then tell them they are wrong. The code posted may not have been exactly what you were looking for, but it was not wrong because it did exactly what the poster said it would do - print out the multiplication table.
    Second, in the future if you ask specific questions rather than posting code and hoping someone will fix it for you, you may one day be able to complete the assignments on your own.
    Here is code that prints what you want and uses a two dimensional array. Please ask questions if you do not understand the code. You will never learn if you just use someone else's code without taking the time to examine or understand it.
    public class MultiTable{  
        public static void main(String[] args)   { 
            int rows = 10;
            int columns = 10;
            int [][] numbers = new int [rows] [columns];
            for(int j = 0; j < rows; j++)   // for each of 10 rows
                for(int k = 0; k < columns; k++)    // for each of 10 columns
                    numbers[j][k] = (j+1) * (k+1);  // calculate row+1 * col+1
            for (int j = 0; j < rows; j++)  // for each of 10 rows
                for (int k = 0; k < columns; k++)   // for each of 10 columns
                    System.out.print(numbers[j][k]+" ");    // print out result
                    if (numbers[j][k] < 10)     // for single digit numbers
                        System.out.print(" ");  // print extra space for better formatting
                System.out.println();       // skip to next line
    }

Maybe you are looking for

  • How to see the print preview of outgoing excise invoice.

    Hi Experts, How to see the print preview of outgoing excise invoice. Thanks, srinivas.

  • Trying to get a forgotten keychain password.

    Hello, I have all my important passwords on my Mac's keychain and that works great. However, I have forgotten one that I need access to on other devices, primarily windows pc's. The problem is that I have forgotten that password and would like to see

  • My imac takes 20 min to boot

    since I've installed lion and ios5 my imac takes 20-30 mins to boot! help!

  • Bug in code HELP!!! please

    When i put a term that isnt in my dictionary it says it isnt in dictionary which is what i want it to do but when i type one that works and it asks to do another one and i click yes or no it says it cant be found, and i cant find what i did wrong. do

  • Reverb/echo sounds disappointing

    Am new to Garage Band (and Mac) - just two weeks... Added reverb to male voice, recorded with internal mic. Although really pleased with GB, I was disappointed with revrb and echo - it sounds thin, and a bit crackly, and even with the slider on 100 p