Reputation: 75
My program doesn't print anything at all.
First I initialized the board in a seperate class (board):
public class Board {
public char board[][] = new char[9][9];
public void main(char[] args){
for(int i=0; i<9; i++){
board[i][0] = '_';
board[i][8] = '_';
}
for(int h=0; h<9; h++){
board[0][h] = '|';
board[8][h] = '|';
}
for(int x=0; x>9; x++){
for(int y=0; y>9; y++){
System.out.println(board[x][y]);
}
}
}
}
Then called it in the main, with a PrintLine
of "Hello World" to check that the code was being accessed. No errors are flagged up but neither does it print anything at all. The Main is below also just to check that i havent done anything simple and stupid:
public static void main(String[] args) {
Ticker T = new Ticker();
Board B = new Board();
for(int x=0; x>9; x++){
for(int y=0; y>9; y++){
System.out.println("Hello World");
System.out.print(B.board[x][y]);
Upvotes: 3
Views: 12574
Reputation: 63955
Besides the incorrect condition in the for loops you should consider using
public class Board {
public char board[][] = new char[9][9];
// this is the constructor, it will be called if you say "new Board()"
// the "main" method you had here will not be called automatically
public Board() {
for (int i = 0; i < 9; i++) {
board[i][0] = '_';
board[i][8] = '_';
}
for (int h = 0; h < 9; h++) {
board[0][h] = '|';
board[8][h] = '|';
}
for (int x = 0; x < 9; x++) {
for (int y = 0; y < 9; y++) {
// just a print so it does not make new lines for every char
System.out.print(board[x][y]);
}
// new line once one column (board[x][0] - board[x][8]) is printed
// note: you proably want to turn around the x and y above since
// I guess you want to print rows instead of columns
System.out.println();
}
}
}
It fixes some problems
main
method with a constructor so the code you wrote there is executedNow if you do
public static void main(String[] args) {
Ticker T = new Ticker();
Board B = new Board(); // << this line triggers printing
// ...
}
you should see some board like thing
Upvotes: 1
Reputation: 343
have a look at
for(int x=0; x>9; x++){
It should be for(int x=0; x<9; x++){
Upvotes: 0
Reputation: 213223
There is problem in your condition of for loop: -
for(int x=0; x>9; x++){
for(int y=0; y>9; y++){
The code inside above loop never gets executed. It should be: -
for(int x=0; x<9; x++){
for(int y=0; y<9; y++){
Upvotes: 1
Reputation: 962
You might want to go for x<9 and y<9 and not > ! ;-) This is the condition loop. If it is false, the loop exit. It is always false in your case.
Upvotes: 0
Reputation: 121961
The terminating conditions on the for
loops are incorrect. Should be <
, not >
. Change to:
for(int x=0; x<9; x++){
for(int y=0; y<9; y++){
Upvotes: 2