Solved

Variable initialization

Posted on 2003-12-05
5
218 Views
Last Modified: 2010-03-31
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
Comment
Question by:Akindo
  • 2
  • 2
5 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 9884158
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
 
LVL 86

Expert Comment

by:CEHJ
ID: 9884173
i.e.

int[][] a, b, c = { { 1,2,3 }, { 1, 2, 3 } };
0
 
LVL 92

Accepted Solution

by:
objects earned 125 total points
ID: 9884757
int[][] a = { { 1,2,3 }, { 1, 2, 3 } }, b = { { 4,5,6 }, { 7, 8, 9 } }, c = { { 0,0,0 }, { 0, 0, 0 } };             
0
 
LVL 92

Expert Comment

by:objects
ID: 9884764
int [][] a = new int[2][3], b=new int[4][5], c=new int[2][5];
0
 
LVL 2

Expert Comment

by:Tols
ID: 9885337
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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
topping3 challenge 14 79
java 8 lambda expresssions exception handling 3 89
fibonacci ten numbers 4 38
arguments to jar 5 26
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question