COP 3330 JAVA

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

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]; }


Ensembles d'études connexes

ExamFX Policy Provisions & Contract Law Terms

View Set

(Pharm) Chapter 26: Narcotics, Narcotic Antagonists and Antimigraine Agents

View Set

Chapter 3 Exam (Earthquake Geology and Seismology)

View Set

Stroke, Stroke NCLEX, HESI- Brain Attack (Stroke), Brain Attack / Stroke, Chapter 45 Care of Critically ILL Patients with Neurologic Problems, Stroke nclex problems, HEC IGGY 45/TBI, stroke, brain attack

View Set

Sleeping disorders- mental health

View Set

Chapter 2: Health History and Interview

View Set

Series 7 Sim Exam - Missed Questions

View Set

Iowa Insurance laws, rules and regulations common to all lines

View Set

Bank Services - H5P 1 - Questions to ask the teller when you open a bank account

View Set

EAQ Week #11 Hematologic problems

View Set

OB: Chapter 13 - Labor and Birth Process

View Set