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

本文提供了一个简单的控制台程序来计算直角三角形的斜边长度。程序接收两个整数输入,代表直角边的长度,并使用勾股定理计算斜边的长度。

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:

 

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

 

程序源代码:

 

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值