"Write the definition of the method doubleArray that initializes the elements of beta to two times the corresponding elements of alpha." is what it says I have to do but i can't figure out exactly how to do it. Any suggestions on how to do this? Here's my code:

import java.util.*;

public class Assignment 8 
{
	static Scanner console = new Scanner(System.in);
		
    public static void main(String[] args) 
    {
    	int[][]inStock = new int[10][4];
    	int[]alpha = new int[20];
    	int[]beta = new int[20];
    	int[]gamma = {11,13,15,17};
    	
    	inputArray(alpha);
    	doubleArray(alpha);
    }
    
    public static void inputArray(int[] listA)
    {
    	System.out.println("Enter 20 numbers:");
    	
    	for (int i = 0; i < listA.length; i++)
    	{
    		listA[i] = console.nextInt();
    	}
    }
    
    public static void doubleArray(int[] listA,int[] listB)
    {
    	
    } 
}

Edited 7 Years Ago by __avd: Added [code] tags. Encase your code in: [code] and [/code] tags.

"Write the definition of the method doubleArray that initializes the elements of beta to two times the corresponding elements of alpha." is what it says I have to do but i can't figure out exactly how to do it. Any suggestions on how to do this? Here's my code:

import java.util.*;

public class Assignment 8
{
static Scanner console = new Scanner(System.in);

public static void main(String[] args)
{
int[][]inStock = new int[10][4];
int[]alpha = new int[20];
int[]beta = new int[20];
int[]gamma = {11,13,15,17};

inputArray(alpha);
doubleArray(alpha);
}

public static void inputArray(int[] listA)
{
System.out.println("Enter 20 numbers:");

for (int i = 0; i < listA.length; i++)
{
listA = console.nextInt();
}
}

public static void doubleArray(int[] listA,int[] listB)
{

}
}

Let's see if I got what you're trying to say.

If you have an array alpha containing n elements, all you have to do is initialize elements of array beta to twice the corresponding elements of alpha. Something like:

beta[0] = alpha[0] * 2
beta[1] = alpha[1] * 2

and so on.

Hope this helps.

This article has been dead for over six months. Start a new discussion instead.