I have been asked to solve this algorithm. And so far this is what I have regarding the java code. I don't know where I am missing something. The problem is as follows: Write a Class called ProblemA003 that output's the following shape (which is the letter X using “$” symbols on a background console):
Simply output to the console (using system.out) Assume a console screen of 25 lines deep and 79 chars wide (see below for the console – it comprises “=” character, with relevant numbering for every 10th column and row. The shape must be centered on this console screen i.e. the middle “$” should be in row 13, column 40 Take as an input to the program a single int parameter (which you can name sizeOfX). This parameter will indicate how many "$" are in the X on either side of the middle “$”. You can simply pass this parameter in via the “main” method. For a clearer description of the parameter sizeOfX, see the example below when sizeOfX = 5 Note: parameter sizeOfX must only take on values of 1-9 (inclusive of 1 and 9). Of course, the bigger the value of sizeOfX, the bigger the size of the X your program must produce.
my method:
private static void MakeACross(int number) {
int start = 0;
int end = number - 1;
for (int i = 0; i < number; i++) {
System.out.print("==");
for (int j = 0; j < number; j++) {
System.out.print("==");
if (start == end && j == i) {
System.out.print('$');
} else if (start == j || end == j) {
System.out.print('$');
} else {
System.out.print(' ');
}
}
start++;
end--;
System.out.println("==");
}
}
Anyone who can help me on how I can further solve this will be highly appreciated.
the output should be ass follows: if the input is 5 (i.e. sizeOfX = 5), your program should produce EXACTLY the output (note the “1” and “2” in the first column of row 10 and 20 respectively)
Aucun commentaire:
Enregistrer un commentaire