java Complete the printTicTacToe method with char parameters horizChar and vertC
ID: 3709529 • Letter: J
Question
java
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:
Hint: To ensure printing of characters, start your print statement as: System.out.println("" + horizChar ...).
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import java.util.Scanner;
public class GameBoardPrinter {
public static void printTicTacToe(char horizChar, char vertChar) {
/* Your solution goes here */
return;
}
public static void main (String [] args) {
printTicTacToe('~', '!');
return;
}
}
code below:
import java.util.Scanner;
public class GameBoardPrinter {
public static void printTicTacToe(char horizChar, char vertChar) {
/* Your solution goes here */
return;
}
public static void main (String [] args) {
printTicTacToe('~', '!');
return;
}
}
Explanation / Answer
GameBoardPrinter.java
import java.util.Scanner;
public class GameBoardPrinter {
public static void printTicTacToe(char horizChar, char vertChar) {
/* Your solution goes here */
for(int i=1;i<=5;i++) {
for(int j=1;j<=5;j++) {
if(i%2==1) {
if(j%2!=1) {
System.out.print("X");
} else {
System.out.print(vertChar);
}
} else {
System.out.print(horizChar);
}
}
System.out.println();
}
return;
}
public static void main (String [] args) {
printTicTacToe('~', '!');
return;
}
}
Output:
!X!X!
~~~~~
!X!X!
~~~~~
!X!X!
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.