Currently Being Moderated
Write static methods which take an array of integers and an integer, and multiply all the integers in
the array by the integer argument. So, for example, if the array argument is 1 3 5 6 8
and the integer argument is 5, the result will be the array: 5 15 25 30 40.
I don't know how to change all the values in the array. I've tried to copy the array first, and then multiply the integers by 5 but I'm not doing it right.
This is what I've got
import java.util.*;
import javax.swing.*;
class multiplyArray
{
public static void main(String[] args) throws Exception
{
Scanner input = new Scanner(System.in);
System.out.println("Enter some numbers (all on one line, separated by spaces):");
String line = input.nextLine();
String[] numbers = line.split(" +");
int[] a = new int[numbers.length];
for(int i=0; i<a.length; i++)
a=Integer.parseInt(numbers[i]);
// String Number=JOptionPane.showInputDialog("Enter a number");
//int Numbers=Integer.parseInt(Number);
System.out.println(copy(a));
}
public static int[] copy(int[] a)
{
int[] b = new int[a.length];
for(int i=0; i<a.length; i++)
b[i]=a[i]*5;
return b;
}
}