2016-08-25 87 views
-1

是否可以使用許多簡單的數組值來聲明多維數組值?如何在java中聲明一個具有兩個或多個單數組的多維數組變量?

char[] alpha1 = {"A","B","C","D","E"}; 
char[] alpha2 = {"F","G","H","I","J"}; 
//Is it possible? Give me a solution for this situation: 
char[][] alpha = { alpha1[] , alpha2[] }; 
+1

char [] [] alpha = {alpha1,alpha2};' – Eran

+3

是的,但''a「'不是'char'它是'String'。你想要''''。另外,編譯器已經知道'alpha1'是'char []'數組,所以你不需要這些'[]'在'{..}'裏面。 – Pshemo

+5

你應該試着編譯它並閱讀錯誤... – xenteros

回答

3

隨着" "你聲明一個字符串。使用' '作爲角色。

但是是有可能的,但你必須刪除[]

char[] alpha1 = {'A','B','C','D','E'}; 
char[] alpha2 = {'F','G','H','I','J'}; 
char[][] alpha = { alpha1 , alpha2 }; 
0

有一對夫婦的方式來聲明多維數組:

  1. 的char [] []的α= {{ 'A','B','C','D','E'},{'F','G','H','I','J'}};
  2. char [] [] alpha = new char [4] []; alpha [0] = new char [3]; alpha [1] = new char [2];