java - Rotate a given String layout clockwise -


given string layout of following form:

x......x ....x..x ....x..x 

rotate above layout 90 degrees clockwise should be:

..x ... ... ... xx. ... ... xxx  

what's easiest way rotate string characters clockwise 90 degrees? string layout can of form , size. if have 100000x100000 size string layout?

public string rotate(string layout) 

or

public void rotate(string layout) 

edit

i fixed mistake pointed out op in comments below. should produce required in original question above.

 public static string rotatestringmatrixby90(string matrix) {     int numberofrows = 3; // leave exercise     int numberofcolumns = 8; // same 1      string newmatrix = "";      int count = 0;     string[] newmatrixcolumns= matrix.split("\n");     while (count < matrix.split("\n")[0].length()) {         (int = newmatrixcolumns.length - 1; > -1; i--) {             newmatrix = newmatrix + newmatrixcolumns[i].charat(count);         }          newmatrix = newmatrix + "\n";         count++;     }      return newmatrix;  } 

and how use it:

    string m = "x......x\n" +                "....x..x\n" +                "....x..x";      system.out.println(m);      m = rotatestringmatrixby90(m);     system.out.println(m); 

(note: assumes using \n separator between rows):


Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -