斯坦福大学开放课程——编程方法 作业2 - 4

来源:互联网 发布:韩国dsp娱乐公司知乎 编辑:程序博客网 时间:2024/05/05 07:12

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 = cwhich 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:

 

呵呵,这题很简单,相信大家都知道如何处理,直接附上源代码

 

程序源代码:

 

原创粉丝点击