r/javahelp • u/Professor762 • Jun 11 '17
Print Tic-tac-toe board Error output
Objective: Complete the printTicTacToe method with char parameters horizChar and vertChar that prints a tic-tac-toe board with the characters as follows. End with newline. Ex: printTicTacToe('~', '!') prints: x!x!x
x!x!xx!x!x Hint: To ensure printing of characters, start your print statement as: System.out.println("" + horizChar ...).
My code:import java.util.Scanner;
public class GameBoardPrinter { public static void printTicTacToe(char horizChar, char vertChar) {
for(int i=1;i<4;i++){ for(int j=1;j<4;j++){ System.out.print("x"); if(j<3){ System.out.print(vertChar); } } System.out.print("\n"); if(i!=3){ for(int j=1;j<6;j++){ System.out.print(horizChar); } } } return; }
public static void main (String [] args) { printTicTacToe('~', '!');
return;} }
Error Out put: Testing with '~', '!' Whitespace differs; see green (missing whitespace) or red (extra whitespace) boxes below. Expected output: x!x!x ~~~~~ x!x!x ~~~~~ x!x!x Your output: x!x!x
~~~~~x!x!x
Where did I go wrong and how do I go about fixing it?
Thanks in advance1
u/desrtfx Out of Coffee error - System halted Jun 11 '17
Do you really expect us to spend our time helping you if you can't even be bothered to produce a properly formatted post?
If you want to print your board - use code formatting. If you want to show your code, use code formatting. See the wonderful sidebar for in-depth instruction on how to properly format your code.
1
u/huck_cussler Jun 11 '17
https://www.reddit.com/r/javahelp/wiki/code_guides