Bifalgorithm post · Computer science one · Normalizing a Number

How can a Java for loop be generalized to sum integers up to another variable?

How can a Java for loop be generalized to sum integers up to another variable? (Computer science one · Normalizing a Number) — "Let’s revisit the example from…

Ideas in this flowchart

  • Généralisation du code de somme des entiers
  • L’exemple est présenté dans la section 4.2.1.
  • L’exemple calcule la somme 1 + 2 + · · · + 10.
  • Le code correspondant est présenté dans le Code Sample 28.8.
  • Le code initial calcule la somme jusqu’à un nombre particulier.
  • Le code peut être généralisé pour effectuer la somme jusqu’à une variable n.
  • Dans cette généralisation, la boucle for utilise n comme borne supérieure.
Feed/

How can a Java for loop be generalized to sum integers up to another variable?

No cover

Channel

Computer science one

1 page

"Let’s revisit the example from Section 4.2.1 in which we computed the sum of integers 1 + 2 + · · · + 10. The code is presented in Code Sample 28.8 We could have easily generalized the code somewhat. Instead of computing a sum up to a particular number, we could have written it to sum up to another variable n, in which case the for loop would instead look like the following."

Flowchart preview
👍
0
0 comments0 shares

Sign in to view and post comments.