CommencerCommencer gratuitement

Increment by one

Countdowns are fun, especially for things like birthdays, product or rocket launches. Now you have the option to simulate one below!

Cet exercice fait partie du cours

Introduction to Java

Afficher le cours

Instructions

  • Use the increment operator ++ to add one to age.
  • Use the decrement operator to subtract one from days.

Exercice interactif pratique

Essayez cet exercice en complétant cet exemple de code.

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!");
    }
}
Modifier et exécuter le code