output - Java make rows and columns -


building rectangular character input , specified column , rows. whitespace in middle.

using standard input string s, int r, int c

private static void printstuff(string s, int r, int c) {      colums(s, c);     rows(s, c, r);     colums(s, c);  }  // straight columns   private static void colums(string cs, int cc) {     (int = 1; <= cc; i++) {         system.out.print(cs);     }  } 

this creates desired whitespace or "" concat string ie making x""""""""x

private static string whitespace(int wc) {     string ws = " ";     (int = 1; <= wc - 3; i++) {         ws += " ";     }     return ws; } 

whitespace built rectangular.

// downwards building  private static void rows(string rs, int rc, int rr) {     string ws = whitespace(rc);     (int = 1; <= rr - 1; i++) {         system.out.println(rs + ws + rs);          // put strings      }  } 

} whitespace , character rows built rectangular. needless failed.

sample output:

xxxx    x   x  x   xxxx   

desired output:

xxxx   x  x   xxxx     

one quick solution below.. cheers

public class main {  public static void main(string[] args) {     string s = "x";     int totalcolumns = 4;     int totalrow = 3;      colums(s, totalcolumns);     rows(s, totalcolumns, totalrow);     colums(s, totalcolumns);   }  private static void colums(string cs, int cc) {     (int = 0; < cc; i++) {         system.out.print(cs);     }  }  private static string whitespace(int tc) {     string ws = " ";     (int = 1; < tc - 2; i++) {         ws += " ";     }     return ws; }  private static void rows(string rs, int tc, int tr) {     system.out.println();     (int = 0; < tr - 2  ; i++) {         system.out.println(rs + whitespace(tc) + rs);     } } 

}


Comments

Popular posts from this blog

ios - iPhone/iPad different view orientations in different views , and apple approval process -

java Extracting Zip file -

C# WinForm - loading screen -