BaşlayınÜcretsiz Başlayın

Increment by one

Increasing or decreasing a value by one is so common in programming that Java provides special operators just for this purpose. These shortcuts make your code cleaner and more efficient. Let's practice counting up and down!

Bu egzersiz

Introduction to Java

kursunun bir parçasıdır
Kursu Görüntüle

Egzersiz talimatları

  • Increase age by one using the increment operator.
  • Decrease days by one using the decrement operator.

Uygulamalı interaktif egzersiz

Bu örnek kodu tamamlayarak bu egzersizi bitirin.

class AddOne {
    public static void main(String[] args) {
    	
        int age = 30;
        int days = 20;
        System.out.println("I'm " + age + " today.");
        
        // Increase the age by 1
        ____;
        
       	// Decrease the days by 1
       	____;
        
        System.out.println("But I'll be " + age + " soon!");
        System.out.println("Only " + days + " to go!");
    }
}
Kodu Düzenle ve Çalıştır