java program using array
I have to write a method that will accept an array as a parameter and return the same array, but with twice as many elements in it.
I wrote the method but when calling it in the main method I have:
Arraypro stuff = new Arrayprof();
int array[] = stuff.exArray(int[] temp);
where exArray(...) is the name of the method.
The error I am getting is
.class expected and ; expected in the line
int array[] = stuff.exArray(int[] temp);
This is the method I have written just in case:
public int[] extArray(int[] temp)
{
int i;
temp= 2 * temp;
return temp;
}
I am not calling it properly .
[697 byte] By [
well1a] at [2007-11-26 23:39:42]

public class ArrayStuff{
public static void main(String args[])
{
int array[ ] = new int[3];
for(int i = 0; i < array.length; i++)
{
System.out.println(array);
}
ArrayStuff stuff = new ArrayStuff();
int array[] = stuff.exArray(int[] temp);
//we have to enter code here to call array and return back as array.Parameter shold be array
// should print the same as before, but have an extra 3 zeroes
for(int i = 0; i < array.length; i++)
{
System.out.println(array);
}
}
public int[] exArray(int[] temp)
{
int i;
temp= 2 * temp;
return temp;
}
}
well1a at 2007-7-11 15:05:42 >

public class ArrayStuff{
public static void main(String args[])
{
int array[ ] = new int[3];
int j;
for(int i = 0; i < array.length; i++)
{
System.out.println(array[i]);
}
ArrayStuff stuff = new ArrayStuff();
int array[] = stuff.extendArray(int[] temp);
// ENTER A LINE OF CODE HERE TO CALL extendedArray
// YOU MUST SUPPLY array AS A PARAMETER AND SAVE
// WHAT IS RETURNED BACK INTO array
// should print the same as before, but have an extra three 0s
for(int i = 0; i < array.length; i++)
{
System.out.println(array[i]);
}
}
public int[] extendArray(int[] temp)
{
int i;
temp[i]= 2 * temp[i];
return temp;
}
}
well1a at 2007-7-11 15:05:42 >

> I did not mean to be arrogant.
No harm done.
Ok, in your extendArray method you will need to create a new array (just as you did in the main method) but then twice as big, and return that new array.
You can get the length of the array like this:
public int[] extendArray(int[] temp)
{
int size = temp.length;
// ... your code ...
}
Good luck.