Solution Review: Compute an Expression Using Maths
In this review, the solution of the challenge 'Compute an expression using maths' from the previous lesson is provided.
We'll cover the following...
We'll cover the following...
Solution
Press + to interact
Java
class HelloWorld {public static void main( String args[] ) {double x = 55.0;double y = 18.0;double z = 51.0;double answer;double sum = Math.pow(x, 2) + Math.pow(y, 2);double sub = sum - Math.abs(z);answer = Math.cbrt(sub);System.out.println(answer);}}
Understanding the Code
Line 7
- The first step is to create a double type variable called
sum
. - This variable stores the addition result of two expressions.