Performing calculations
You can use numbers and variables to do maths in Java! Time to practice some basic calculations.
Este exercício faz parte do curso
Introduction to Java
Instruções do exercício
- Save the result of
5plus6into theintcalledvarA. - Save the result of
varAminus3.5into thedoublecalledvarB. Use thevarA. - Save the result of
3times3into theintcalledvarC. - Save the result of
varCdivided by3into theintcalledvarD1and also to adoublecalledvarD2.
Exercício interativo prático
Experimente este exercício completando este código de exemplo.
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);
}
}