Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Variable initialization

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
egit plugin on eclipse 8 82
throw exception 21 58
Running JavaFX on JDeveloper 12C 1 51
ejb entity bean example 2 7
INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

792 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