LoslegenKostenlos loslegen

Odd summing

You wish to know how quickly the sum of the odd number grows up to 100. Why not write a code that does that?

Diese Übung ist Teil des Kurses

Intermediate Java

Kurs anzeigen

Anleitung zur Übung

  • Enter the correct keyword to create the loop.
  • Call the appropriate variable to store the total reached.
  • Use the fitting operation to have i increase by 2 each run.

Interaktive Übung

Vervollständige den Beispielcode, um diese Übung erfolgreich abzuschließen.

class Adder {
  public static void main(String[] args) {
    int total = 0;
    int i = 1;

    // Enter the correct keyword to create the loop
    ____ (total < 100) {
      // Call the appropriate variable to store the total reached
      ____ += i;
      // Use the fitting operation to have i increase by 2 each run
      i ____ 2;
    }

    System.out.println("We reach " + total + " when summing up to " + i);
  }
}
Code bearbeiten und ausführen