Increment by one
Countdowns are fun, especially for things like birthdays, product or rocket launches. Now you have the option to simulate one below!
Diese Übung ist Teil des Kurses
Introduction to Java
Anleitung zur Übung
- Use the increment operator
++
to add one toage
. - Use the decrement operator to subtract one from
days
.
Interaktive Übung
Versuche dich an dieser Übung, indem du diesen Beispielcode vervollständigst.
class AddOne {
public static void main(String[] args) {
int age = 30;
int days = 20;
System.out.println("I'm " + age + " today.");
// Increment the age by 1
____;
// Decrement the days by 1
____;
System.out.println("But I'll be " + age + " soon!");
System.out.println("Only " + days + " to go!");
}
}