java - How do I turn the diagonal line to the other side? -
i have code it's printing diagonal this...i wanted go top right bottom left, idea how turn it?
* * * * *
code:
class diagonal { public static void main(string args[]) { int row, col; string spaces = " "; for( row = 1; row < 6; row++) { system.out.println(spaces +"*"); spaces += " "; } } }
you construct diagonal inserting space each additional row. therefore, if start number of rows , remove space should inversion. need clean how we're doing spaces can subtract number per row more easily.
class diagonal{ public static void main(string args[]) { int row, col; for( row = 6; row > 0; row--) { (int x = 0; x < row; x++) { system.out.print(" "); } system.out.print("*\n");//note carriage return } } }
Comments
Post a Comment