12.2.4 1 test passed All tests passed Challenge 12.2.4: Modify an array\'s eleme
ID: 3811229 • Letter: 1
Question
12.2.4 1 test passed All tests passed Challenge 12.2.4: Modify an array's elements. Activity Double any element's value that is less than minVal. Ex: lf minVal 0, then dataPoints 2, 12, 9, 20 becomes (4, 12, 18, 20 1 public class StudentScores 1 2 public static void main CString CJ args) final int NUM POINTS 4; int[] dataPoints new intCNUM POINTS]; int minval 0 int i 0; dataPoints D01 2 data PointsC1] 12 dataPointsC2J 9; 100 dataPoints[3] 20 11 12 minval 10; 13 Your solution goes here 16 for Ci 0; i NUM POINTS ++i) 18 System.out.print(dataPoints[i] 19Explanation / Answer
StudentScores.java
public class StudentScores {
public static void main (String [] args) {
final int NUM_POINTS = 4;
int[] dataPoints = new int[NUM_POINTS];
int minVal = 0;
int i = 0;
dataPoints[0] = 2;
dataPoints[1] = 12;
dataPoints[2] = 9;
dataPoints[3] = 20;
minVal = 10;
/* Your solution goes here */
for (i = 0; i < NUM_POINTS; ++i) {
if(dataPoints[i] < minVal){
dataPoints[i] = dataPoints[i]*2;
}
System.out.print(dataPoints[i] + " ");
}
System.out.println();
return;
}
}
Output:
4 12 18 20
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.