java - How to organize a single array into a two-dimensional one? -
i trying split 1 dimensional array of display modes 2-dimensional string array, though have encountered trouble got point of splitting sorted array of display modes. question: how can split single array, sorted, 2 dimensional array? code (sorry weird variable names):
public static string[][] organizedisplaymodes (displaymode[] modes) { int iter = 0; int deltaiter = 0; int rows = 0; int columns = 0; string[][] tobe; //bubble sorting (int = 0; < modes.length - 1; a++) { for(int = 0; < modes.length - 1; i++) { if (modes[i].getwidth() < modes[i+1].getwidth()) { displaymode change = modes[i]; modes[i] = modes[i+1]; modes[i+1] = change; } } } for(int = 0; < modes.length - 1; i++) { if ((modes[i].getwidth() == modes[i+1].getwidth()) && (modes[i].getbitsperpixel() < modes[i+1].getbitsperpixel())) { displaymode change = modes[i]; modes[i] = modes[i+1]; modes[i+1] = change; } } for(int = 0; < modes.length - 1; i++) { if ((modes[i].getwidth() == modes[i+1].getwidth()) && (modes[i].getfrequency() < modes[i+1].getfrequency())) { displaymode change = modes[i]; modes[i] = modes[i+1]; modes[i+1] = change; } } for(int = 0; < modes.length; i++) { displaymode current = modes[i]; system.out.println(i + ". " + current.getwidth() + "x" + current.getheight() + "x" + current.getbitsperpixel() + " " + current.getfrequency() + "hz"); } //fit string array (int = 0; < modes.length - 1; i++) { if (!(modes[i].getwidth() == modes[i+1].getwidth())) { rows += 1; deltaiter = - deltaiter; if (deltaiter > columns) columns = deltaiter; } } //split displaymode array two-dimensional string 1 here tobe = new string[rows][columns]; (int = 0; < rows; i++) { (int = 0; < columns; a++) { if((modes[iter].getwidth() == modes[iter+1].getwidth())) { tobe[i][a] = iter + ". " + modes[iter].tostring() + " "; } else break; if (!(iter >= 68)) iter += 1; } if (iter >= 68) break; } tobe[rows-1][columns-1] = (iter + 1) + ". " + modes[iter].tostring() + " "; //test see works (int = 0; < rows; i++) { (int = 0; < columns; a++) { if(tobe[i][a] != null) system.out.print(tobe[i][a]); else break; } system.out.println(""); } system.exit(0); return null; }
the output looks this:
0. 1440x900x32 75hz 1. 1440x900x16 75hz 2. 1440x900x32 60hz 3. 1440x900x16 60hz
with of different possible resolutions. basically, i'm trying make readable list of different resolutions, user can select desired one. thank you.
how storing information in different manner? when made transition c java used use multi-dimensional arrays quite bit, it's pain.
public class screentype implements comparable { int width; int height; int color; // not sure 1 for, assuming 32/16 bit color int hertz; public screentype(int w, int h, int c, int h) { width = w; height = h; color = t; hertz = h; } // remember maintain transitive property, // see jdk documentation comparable @override public int compareto(tuple other) { } // getters , setters , whatnot @override public string tostring() { return width + "x" + height + "x" + color+ " " + hertz + "hz"; } }
then store screen data , use arraylist of screentypes which, if remember right, sort based on overriding of compareto()
Comments
Post a Comment