Question: Six integers are read from input and stored into the array myArray. Write a static method addNumToElements ( ) that takes an integer array parameter

Six integers are read from input and stored into the array myArray. Write a static method addNumToElements() that takes an integer array parameter and adds 3 to each element in the array.
Ex: If the input is 206070154535, then the output is:
Input array: 206070154535 Output array: 236373184838
import java.util.Scanner;
public class ModifyArray {
/* Your code goes here */
public static void printArr(int[] arr){
int i;
for (i =0; i < arr.length; ++i){
System.out.print(arr[i]+"");
}
System.out.println();
}
public static void main(String[] args){
Scanner scnr = new Scanner(System.in);
final int NUM_ELEM =6;
int[] myArray = new int[NUM_ELEM];
int i;
int userNum;
for (i =0; i < myArray.length; ++i){
myArray[i]= scnr.nextInt();
}
System.out.print("Input array: ");
printArr(myArray);
addNumToElements(myArray);
System.out.print("Output array: ");
printArr(myArray);
}
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!