我一直在試圖打印出一個5尖的星,但我一直在收到編譯錯誤。開始Java:使用數組打印出一個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]
?
* 「收到編譯錯誤。」 *複製/粘貼錯誤爲[編輯的問題](http://stackoverflow.com/posts/16116714/edit)。還爲代碼塊使用一致的邏輯縮進。代碼的縮進旨在幫助人們理解程序流程! – 2013-04-20 04:55:16