我試圖讓程序接受兩個3x3矩陣,然後添加或乘以它們。我得到了很多三個不同的錯誤。很多「.class期望」和「不是一個聲明」
首先,「預期的.class」錯誤,當我試圖創建一個字符串,以顯示這些行整個矩陣一堆:
strA = "\n\n|" + r1a[];
strA += "|\n|" + r2a[];
strA += "|\n|" + r3a[];
它,當我做其他2次重複迭代對於strB和strC。
當我擡頭一看這個錯誤,我發現這是可能的,爲什麼它的發生,其中沒有一個似乎是問題的掃描我的代碼時:
Usually this is just a missing semicolon,
sometimes it can be caused by unbalanced() on the previous line.
sometimes it can be cause by junk on the previous line. This junk might be far to the right off the screen.
Sometimes it is caused by spelling the keyword if incorrectly nearby.
Sometimes it is a missing + concatenation operator.
我的下一個問題是,當我嘗試以創建最終的矩陣。我得到「沒有聲明」的混合物和「預期」在此代碼中的錯誤:
r1c[] = r1a[] + r1b[];
r2c[] = r2a[] + r2b[];
r3c[] = r3a[] + r3b[];
感謝tacp爲此解決!
的錯誤備用;編譯器首先在r1c []的左括號處用箭頭產生「不是語句」,然後在r1c [] =之間的空格處帶有「; expected」。第二次和第三次出現只是移動代碼,重複該位置(左括號,空格)。
我這是怎麼聲明的所有我的變量的:
import javax.swing.JOptionPane;
public class Matrices
{
public static void main(String[] args)
{
int i = 0;
double[] r1a = new double[3]; //row 1 of matrix a
double[] r2a = new double[3]; //row 2 of matrix a
double[] r3a = new double[3]; //row 3 of matrix a
double[] r1b = new double[3]; //row 1 of matrix b
double[] r2b = new double[3]; //row 2 of matrix b
double[] r3b = new double[3]; //row 3 of matrix b
double[] r1c = new double[3]; //row 1 of matrix c
double[] r2c = new double[3]; //row 2 of matrix c
double[] r3c = new double[3]; //row 3 of matrix c
String strInput, //holds JOption inputs
strA, //holds matrix A
strB, //holds matrix B
strC; //holds matrix C
我真的不知道我做錯了。這裏是我所有的代碼.. code:p
這可能是非常基本的東西,但這是我編程的第一個學期,以任何語言編寫。所以我的故障排除技巧是最小的,我的實際編碼技能也是如此。 haha
因此,非常感謝您的幫助!
什麼'R1A [] + r1b []'應該是?並添加'r1a []'到一個字符串? – 2013-04-21 22:58:48
你想追加到方法體外的類變量字符串嗎?這會導致你看到的一些編譯器錯誤。在你的問題中添加你班級的***簽名,以及所有變量的聲明。爲了簡潔起見,您可以省略這些方法。 – Perception 2013-04-21 22:58:50
這就是你如何聲明多維數組例如:'double [] [] anArray = new double [5] [5]'。這將創建5行和5列。並用他們的行列組合引用它們。 – 2013-04-21 23:04:52