i am trying to do something very simple but i keep getting identifier errors. i want to initialize a variable, a if statement and an array within a class, this is a much simpler version of my own maze program that i am showing you to illustrate the basic code setup.what am i doing wrong if anyone could show me how to write the code so the compiler wont give me errors that would be great, thank you very much
public class mazet{
public static void main(String a[]){
class square {
boolean sides[]=new boolean[]{true, false, false, false};
int topx,topy,rightx,righty,downx,downy,leftx,lefty;
if (sides[0]=false);
{
topx=0;
}
else if (sides[0]=true);
{
topx= 40;
}
}}
答案 0 :(得分:0)
You only need one class (mazet or square) declare outside main method.
class square {
static boolean sides[] = new boolean[]{true, false, false, false};
static int topx, topy, rightx, righty, downx, downy, leftx, lefty;
public static void main(String a[]) {
if (sides[0] = false) {
topx = 0;
} else {
topx = 40;
}
System.out.println(topx);
}
}
答案 1 :(得分:0)
Remember Java is a typified language and what differentiates declaring a variable/function to not is saying its type.
Instead of saying:
topx = 0;
on declaration, you should be saying:
int topx = 0;
Hope this helps!