• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 227
  • 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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

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