Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 224
  • Last Modified:

Variable initialization

Is there a way to initialize multiple values at the same time while also giving them
a value...
for ex.

instead of

int [][] a,b,c;

a= new int..
b=new int..
c= new int...

so instead of that combine the initializations into arrays into one line?
0
Akindo
Asked:
Akindo
  • 2
  • 2
1 Solution
 
CEHJCommented:
If you were to combine them, AFAIK, there's no way to do that without them becoming the same array. Do you want that?
0
 
CEHJCommented:
i.e.

int[][] a, b, c = { { 1,2,3 }, { 1, 2, 3 } };
0
 
objectsCommented:
int[][] a = { { 1,2,3 }, { 1, 2, 3 } }, b = { { 4,5,6 }, { 7, 8, 9 } }, c = { { 0,0,0 }, { 0, 0, 0 } };             
0
 
objectsCommented:
int [][] a = new int[2][3], b=new int[4][5], c=new int[2][5];
0
 
TolsCommented:
for (int i=0;i<a.length;i++)
    for (int j=0;j<a[i].length;j++)
        a[i][j] = getValue(i,j);

....;-)

0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now