i had to draw an X shape with x's, i managed to do it but the problem is that i cant seem to figure out how to adjust the width of the "X". Can anyone help?
__________________________________________________ __________________________________________________ _____________________________public class JavaApplication9 { public static void printX(int x) { char[] chars = new char[x]; for (int i = 0; i < x; i++) { chars[i] = 'x'; chars[x - 1 - i] = 'x'; for (int j = 0; j < x; j++) { if (j == i || j == (x - 1 - i)) { continue; } chars[j] = ' '; } System.out.println(new String(chars)); } } }
Current Output:
when i run the program is run i can enter the height(in this case 6)
__________________________________________________ __________________________________________________ _______________________________x x x x xx xx x x x x
I also want to adjust the width. For example:
(something like that)xxx xxx xxx xxx xxxxxx xxxx xxxx xxxxxx xxx xxx xxx xxx