answersLogoWhite

0


Best Answer

import java.util.Scanner; class Addition

{

public void Addition()

{

Scanner s = new Scanner(System.in); int a[][] = new int[3][]; int b[][] = new int[3][]; int c[][] = new int[3][]; for(int i=0;i<3;i++)

{

a[i] = new int[3]; b[i] = new int[3];

c[i] = new int[3];

}

System.out.println("Enter the elements of var size array a"); for(int i=0;i<3;i++)

{

for(int j=0;j<3;j++)

{

a[i][j] = s.nextInt();

}

}

System.out.println("Enter the elements of var size array b"); for(int i=0;i<3;i++)

{

for(int j=0;j<3;j++)

{

b[i][j] = s.nextInt();

}

}

for(int i=0;i<3;i++)

{

for(int j=0;j<3;j++)

{

c[i][j] = a[i][j]+b[i][j];

}

}

System.out.println("The resultant matrix is: "); for(int i=0;i<3;i++)

{

for(int j=0;j<3;j++)

{

System.out.print(c[i][j]+" ");

}

System.out.println();

}

}

}

public class AdditionTest

{

public static void main(String args[])

{

Addition a = new Addition();

a.Addition();

}

}

User Avatar

Wiki User

14y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

14y ago

You can use java.util.ArrayList, which is similar to an array but will grow in size as you add items to it. ArrayList arrayName = new ArrayList(4); arrayName is the name of the array, it can be anything you want.

String is the data type, you can use other things, such as Integer.

The number 4 at the end is the initial size of the ArrayList (it will grow as you add elements), if you leave it blank it will default to 10. You can add items: arrayName.add("Hello");

Add items to a specific spot: arrayName.add(2, "Hello");

Delete items: arrayName.remove(2, "Hello");

Get items: arrayName.get(2) The great thing about adding and deleting is that it will shift all of the other items to the left or right, so you won't have blank holes in the array. You can add something right into the middle of the array, it won't overwrite what's there, it will shift items to the right to make room for the new item.

There is also more which you can find here: http://java.sun.com/javase/6/docs/api/

Just find "ArrayList" in the left panel.

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Write a Java program which create variable size array in Java?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Can you give an example of array using character variable in c program?

the example of array over charcter variables is char ["string"]


What is the base address of an array in c program?

the address of variable (pointer) that contains array


You can use a variable to declare an array's size true or false?

True and false in the same time, because even so you can declare array size using notation for variables you have use constwhich makes your variable basically a constant:const int arraySize = 10;In Java, you can use any expression to define the array size, when you create the array. Once you create an Array object, however, you can't redimension it - but you can create a new Array object and destroy the old one.


How do you write a C Program to fill up an Integer Array?

Reference:cprogramming-bd.com/c_page1.aspx# array programming


How do you write a program to read set of numbers using by an array and display the ascending order of the given input numbers?

To write a C++ program to display the student details using class and array of object.


Could you Write a program for 8086 microprocessor that displays on the monitor the average of 2 numbers from an array?

How to write a program for mouse in microprocessor?


How do you initialize an array variable in java program?

An array in java is a collection of items stored into a single unit. The array has some number of slots (elements), each slot in the array can hold an object or a primitive value. Arrays in java are objects that can be treated just like other objects in the languageArrays can contain any type of element value , but we can't store different types in a single array. We can have an array of integers or an array of strings or an array of arrays.To create an array in java ,use three steps1. Declare a variable to hold the array2. Create a new array object and assign it to the array variable3. Store things in that array


What is the difference between an array element and a variable?

Array elements are all members of the same variable, indexed in a logical manner. variables are distinct objects which must be referred to distinctly. The main functional difference is that a program can iterate over an array without the programmer knowing the original size of the array or explicitly which member to access.


What is the best way to write an array to a file in PHP?

The serialize() function is used to create a storable representation of a variable in PHP.To store an array to a file, you first use the serialize() function to change an array into a string. Save the string in a file using file I/O, so fwrite() or a similar function. When reading it use unserialize() to get the original array again.


Is an array is a collection of characters that can be fixed or variable?

No. An array is a collection of objects of any type, such as doubles, not just characters. You can even have arrays of arrays, or arrays of structs. In C, the size of an array is fixed, but it is possible to write code that will allow you to manually make it variable in size.


Is there a way to use a variable to declare the size of an array in true basic?

! variable to declase the size of an array in True Basic ! set up a dummy value for array - any initial value &gt; 0 is fine. DIM array$(999) ! ask the user for the length of the array INPUT PROMPT "Enter array size " :size ! resize the array with user defined length MAT REDIM array$(size) ! program end END


What is an array and how do you create one How do you access information or elements contained in an array?

An array is:simply a collection of similar objectsHow you create one: (I think)Basically you receive or copy an image and place it in an array and assign it an mage Areray name.How you access info and elementsIt can be accessed by means of a variable name and an index.