Performing calculations
You can use numbers and variables to do maths in Java! Time to practice some basic calculations.
Diese Übung ist Teil des Kurses
Introduction to Java
Anleitung zur Übung
- Save the result of
5
plus6
into theint
calledvarA
. - Save the result of
varA
minus3.5
into thedouble
calledvarB
. Use thevarA
. - Save the result of
3
times3
into theint
calledvarC
. - Save the result of
varC
divided by3
into theint
calledvarD1
and also to adouble
calledvarD2
.
Interaktive Übung
Versuche dich an dieser Übung, indem du diesen Beispielcode vervollständigst.
class BasicMaths {
public static void main(String[] args) {
// Save the result of 5 plus 6 to varA
int varA = ____ ____ ____;
// varB is varA minus 3.5
double varB = ____;
// varC is 3 times 3
____;
// varD1 is varC divided by three, as int
int varD1 = ____;
// varD2 is varC divided by three, as double
____;
System.out.println("int varD1: " + varD1);
System.out.println("double varD2: " + varD2);
}
}