Solved

Variable initialization

Posted on 2003-12-05
5
217 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
network + 7 80
Running Jira on Raspberry PI 2? 3 265
Starting to learn JAVA, 7 59
ArrayIndexOutOfBoundException 9 68
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…

895 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now