4.
In high-school geometry, you learned the Pythagorean theorem for the relationship of the lengths of the three sides of a right triangle: a2 + b2 = c2 which can alternatively be written as: c = sqrt(a2 + b2 ) .
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 statement
double 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:

呵呵,这题很简单,相信大家都知道如何处理,直接附上源代码
程序源代码:
本文提供了一个简单的控制台程序来计算直角三角形的斜边长度。程序接收两个整数输入,代表直角边的长度,并使用勾股定理计算斜边的长度。
349

被折叠的 条评论
为什么被折叠?



