RE: first quick java program

  • From: "Michael Malver" <mmalver@xxxxxxxxx>
  • To: <programmingblind@xxxxxxxxxxxxx>
  • Date: Tue, 22 Mar 2011 12:57:49 -0500

Declare an instance of your class, and call PrintBord off of the instance.
Haven't looked at your code, but I bet htat's the problem.
You can't call non-static methods from main.


-----Original Message-----
From: programmingblind-bounce@xxxxxxxxxxxxx
[mailto:programmingblind-bounce@xxxxxxxxxxxxx] On Behalf Of Littlefield,
Tyler
Sent: Tuesday, March 22, 2011 12:55 PM
To: programmingblind@xxxxxxxxxxxxx
Subject: first quick java program

Hello all:
I am writing a quick tic-tac-toe game, and so far I have Java printing 
out the board. I'm curious if 1) this is the right way to go about it, 
and 2), i'm noticing that I have to declare PrintBoard as static. Is 
there a way around that?
Thanks,
public class ttt
{
public static void PrintBoard(String[] board)
{
int i, j;
System.out.println("|-|-|-|");
for (i= 0; i < 3; i++)
{
for (j = 0; j < 3; j++)
{
System.out.print(board[i*j]+"|");
}
System.out.println("|-|-|-|");
}
}

public static void main(String[] args)
{
int i;
String[] board = new String[9];
for (i = 0; i < 8; i++)
{
board[i] = " ";
}
PrintBoard(board);
}

}

-- 

Thanks,
Ty

__________
View the list's information and change your settings at 
//www.freelists.org/list/programmingblind


__________
View the list's information and change your settings at 
//www.freelists.org/list/programmingblind

Other related posts: