Question: Integer numValues is read from input, representing the number of integers to be read next. Then, the remaining integers are read and stored into array

Integer numValues is read from input, representing the number of integers to be read next. Then, the remaining integers are read and stored into array numbersArray. For each element in numbersArray that is odd, assign the element with the element's current value plus 1.
Ex: If the input is:
3
711196
then the output is:
Original numbers: 711196
New numbers: 721296
Note: (x %2!=0) returns true if x is odd.
import java.util.Scanner;
public class ArrayUpdate {
public static void main(String[] args){
Scanner scnr = new Scanner(System.in);
int[] numbersArray;
int numValues;
int i;
numValues = scnr.nextInt();
numbersArray = new int[numValues];
for (i =0; i < numbersArray.length; ++i){
numbersArray[i]= scnr.nextInt();
}
System.out.print("Original numbers: ");
for (i =0; i < numbersArray.length; ++i){
System.out.print(numbersArray[i]+"");
}
System.out.println();
/* Your code goes here */
System.out.print("New numbers: ");
for (i =0; i < numbersArray.length; ++i){
System.out.print(numbersArray[i]+"");
}
System.out.println();
}
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

The question is complete Lets proceed with the solution step by step To solve this problem where we have to modify the array by incrementing the odd n... View full answer

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 Databases Questions!