Friday, 15 July 2011

java - Trying to wrap my head around 3 nested if statments -


Say I have an array of 5 stars and is related to that array, it has 3 arrays of all integers of the same size. String A [] = new string [5] int x [] = new int [5] int y [] = new int [5] int j [] = new int [5]

So that [0], x [0], y [0], z [0] are related to the same thing. I want to know which index (ss) holds the highest number in x [] if one The more people have the same highest number, then among them the greatest number is [] and if more than one has the same highest number which is the highest in one [] (believe it

This is best if it only checks the first 2 terms {If (x [i] & Gt; = Max) {if (x [i] == max) {if if i <= p> (y [i] & gt; = max) {max = x [i]; Winner = a [i]; max = or [i];}} and {max = x [i]; winner = team [i]; max = y [i];}} < P> then this is my new code

  Fixed Ent Plan Value () {for (int i = 0; i & lt; diff = y [i] - y [max];} (Diff == 0) {diff = y = ii} - x [max]; if (diff == 0) == 0) {diff = z [i] - z [ Purges];} if (diff & gt; 0) {Ma X = i}} return max;   

}

if string [n] related to int [n] for each N, then in fact you should write them correctly, they need to sort them by making comparative .

  Class Thing applies Comparable & lt; Thing & gt; {Last String A; Last int x; Final Ent Y; Last Int Zed; Public talk (string a, int x, int y, int z) {this.a = a; This.x = x; this. Y = y; This.z = z; } Compare @ Override Public Int (Thing O) {int diff = o.x - x; If (diff == 0) {diff = o.y - y; } If (diff == 0) {diff = o.z - z; } Return gap; } @ Override public string toting () {return "{" + a + "," + x + "," + y + "," + z + "}"; }} Public static integer maximum (thing [] things) {// NB - this should actually compare int max = 0; For (int i = 1; i & lt; things.length; i ++) {int diff = Things [i] .x - Things [max] .x; If (diff == 0) {diff = things [i] .y - things [max] .y; } If (diff == 0) {diff = things [i] .z - things [max] .z; } If (diff> 0) {// highest max = i; }} Return max; } Public Zero Test () {Cheung [] Things = New Thing [6]; Things [0] = New Thing ("Hello", 1, 2, 3); Things [1] = New Thing ("There", 1, 2, 4); Things [2] = New Thing ("Everyone", 0, 2, 3); Things [3] = New Thing ("How", 9, 0, 3); Things [4] = New Thing ("are", 8, 9, 3); Things [5] = New Thing ("You", 7, 2, 3); System.out.println ("Before:" + Arrays.toString (Things)); System.out.println ("Max:" + things [max (things)]); Arrays.sort (things); System.out.println ("Sorted:" + Arrays.toString (Things)); }  

No comments:

Post a Comment