I am trying to print pattern The logic of printing pattern is correct, but I cant seem to print it correctly in a format. It should be printing like this without ()
(---------------)
pattern
(---------------)
but mine is printing like this without ()
pattern
(---------------)
(---------------)
// call and print upper left method
System.out.println("Running upperLeft()");
upperLeft(charArray);
print(charArray);
This is my print method
public static void print (char [][] character)
{
// declare and instantiate array
//charArray = new char [arrayNumber][arrayNumber];
// print the top dash (-) symbols
for (int i = 0; i < character.length; i++)
System.out.print("--");
// print the pattern
for (int r = 0; r < character.length; r++) {
System.out.println();
for (int c = 0; c < character.length; c++) {
System.out.printf("%2s", character[r] [c]);
}
}
// add empty line
System.out.println();
// print the bottom dash (-) symbols
for (int j = 0; j < character.length; j++)
System.out.print("--");
}
and this is my upperLeft() method
public static void upperLeft(char [][]charArray)
{
// declare and instantiate array
charArray = new char [arrayNumber][arrayNumber];
// print upper left pattern
for(int r = 0; r < charArray.length; r++){
for(int c = 0; c < charArray.length; c++){
if(c < arrayNumber / 2 && r < arrayNumber/2) {
charArray[r][c] = symbol;
System.out.print(charArray[r][c] + " ");
}
else{
charArray[r][c] = ' ';
System.out.print(charArray[r][c] + " ");
}
}
System.out.println();
}
}
let me know if you need more info or full code.
Thanks in advance
Aucun commentaire:
Enregistrer un commentaire