203k views
4 votes
Double any element's value that is less than minValue. Ex: If minValue = 10, then dataPoints = {2, 12, 9, 20} becomes {4, 12, 18, 20}.

import java.util.Scanner;
public class StudentScores {
public static void main (String [] args) {
Scanner scnr = new Scanner(System.in);
final int NUM_Points = 4;
int[] dataPoints = new int[NUM_POINTS];
int minValue;
int i;
minValue = scnr.nextInt();
for (i = 0; i < dataPoints.length; ++i) {
dataPoints[i] = scnr.nextInt();
}
/* Your solution goes here */
for (i = 0; i < dataPoints.length; ++i) {
System.out.print(dataPoints[i] + " ");
}
System.out.println();
}
}

User NPadrutt
by
7.2k points

1 Answer

3 votes

Answer:

Following are the code to this question:

for(i=0;i<dataPoints.length;++i) //define loop to count array element

{

if(dataPoints[i]<minValue) // define condition that checks array element is less then minValue

{

dataPoints[i] = dataPoints[i]*2; //double the value

}

}

Step-by-step explanation:

Description of the code as follows:

  • In the given code, a for loop is declared, that uses a variable "i", which counts all array element, that is input by the user.
  • Inside the loop and if block statement is used, that check array element value is less then "minValue", if this condition is true.
  • So, inside the loop, we multiply the value by 2.
User VnoitKumar
by
8.2k points
Welcome to QAmmunity.org, where you can ask questions and receive answers from other members of our community.