LoslegenKostenlos loslegen

Performing calculations

Math is at the heart of programming - from simple addition to complex formulas. Java provides operators that let you perform calculations just like you would with a calculator. Let's put these operators into action!

Diese Übung ist Teil des Kurses

Introduction to Java

Kurs anzeigen

Anleitung zur Übung

  • Save the result of 5 plus 6 into the int called varA.
  • Save the result of varA minus 3.5 into the double called varB.
  • Save the result of 3 times 3 into the int called varC.
  • Save the result of varC divided by 3 into the int called varD1 and also to a double called varD2.

Interaktive Übung

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

class BasicMaths {
    public static void main(String[] args) {
    
    	// Save the result of 5 plus 6 into varA
        int varA = ____ ____ ____;
        
        // Save the result of varA minus 3.5 into varB
        double varB = ____;
        
        // Save the result of 3 times 3 into varC
        ____; 
        
        // Save the result of varC divided by 3 into varD1
        int varD1 = ____;
        
        // Save the result of varC divided by 3 into varD2
        ____;   
        
        System.out.println("int varD1: " + varD1);
        System.out.println("double varD2: " + varD2);
	}
}
Code bearbeiten und ausführen