我一直在尝试打印出一个 5 角星,但我不断收到编译错误。
public class star
{
public static void main(String[] args)
{
int[][] star1 =new int[first][last];
int first = 5;
int last = 2;
for(int i = 0; i < 5; i++)
{
for(int j = 0; j < 2; j++)
(char) star1[i][j] == "*";
System.out.println(star1[i][j]);
}
}
}
}
这些是我得到的错误:
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
first cannot be resolved to a variable
last cannot be resolved to a variable
Syntax error on token ")", throw expected after this token
Incompatible operand types char and String
j cannot be resolved to a variable at star.main(star.java:7)
我不明白为什么我们不能说(char) star1[i][j] == "*"
我还能如何分配星号star1[i][j]
?