In high-school geometry, you learned the Pythagorean theorem for the relationship of the lengths of the three sides of a right triangle:

a^{2}+ b^{2}= c^{2}

which can alternatively be written as:

c = √(a^{2}+ b^{2})

Most of this expression contains simple operators covered in Chapter 3. The one piece that’s missing is taking square roots, which you can do by calling the standard function Math.sqrt. For example, the statementdouble y = Math.sqrt(x);sets y to the square root of x.

Write a ConsoleProgram that accepts values for a and b as ints and then calculates the solution of c as a double. Your program should be able to duplicate the following sample run:

Continue reading “cs106a – Assignment #2 – Task #4”