COP 3330 JAVA
Write a loop that subtracts 1 from each element in lowerScores. If the element was already 0 or negative, assign 0 to the element. Ex: lowerScores = {5, 0, 2, -3} becomes {4, 0, 1, 0}.
// for ( i = 0; I < SCORES_SIZE; i++){ If ( I == (SCORES_SIZE - 1)) { newScores [i] = oldScores [0]; } Else { newScores[i] = oldScores [i+1]; } }
Write a loop that subtracts 1 from each element in lowerScores. If the element was already 0 or negative, assign 0 to the element. Ex: lowerScores = {5, 0, 2, -3} becomes {4, 0, 1, 0}.
for ( i = 0; i < lowerScores.length; ++i) { if (lowerScores[i] > 0) { lowerScores[i] = lowerScores[i] - 1; } else { lowerScores[i] = 0; } }
For any element in keysList with a value greater than 50, print the corresponding value in itemsList, followed by a space. keysList[] itemsList[]
for (i = 0; I < SIZE_LIST; i++) { If (keysList [i] <= 50) { keysList[i] = itemsList [i]; } Else { System.out.print(ItemsList[i] + " "); } } System.out.println(""); } }
Write a loop that sets each array element to the sum of itself and the next element, except for the last element which stays the same. Be careful not to index beyond the last element. Ex: Initial scores: 10, 20, 30, 40 Scores after the loop: 30, 50, 70, 40 The first element is 30 or 10 + 20, the second element is 50 or 20 + 30, and the third element is 70 or 30 + 40. The last element remains the same.
for( i = 0; i < bonusScores.length-1; ++i) { bonusScores[i] += bonusScores[i+1]; }