Java求一个分数数列的前20项之和的实现代码
作者:mdxy-dxy 时间:2021-08-22 14:59:58
题目:有一分数序列:2/1,3/2,5/3,8/5,13/8,21/13...求出这个数列的前20项之和。
程序分析:请抓住分子与分母的变化规律。
程序设计:
public class test20 {
public static void main(String[] args) {
float fm = 1f;
float fz = 1f;
float temp;
float sum = 0f;
for (int i=0;i<20;i++){
temp = fm;
fm = fz;
fz = fz + temp;
sum += fz/fm;
//System.out.println(sum);
}
System.out.println(sum);
}
}
标签:Java,分数,数列
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Springboot2.0处理自定义异常并返回json
2021-06-01 03:42:24
![](https://img.aspxhome.com/file/2023/0/62140_0s.png)
JVM教程之内存管理和垃圾回收(三)
2023-11-10 15:49:54
![](https://img.aspxhome.com/file/2023/2/59352_0s.jpg)
java序列化和java反序列化示例
2023-11-24 04:01:03
MyBatis-Plus多表联查的实现方法(动态查询和静态查询)
2023-11-23 22:26:45
![](https://img.aspxhome.com/file/2023/9/59839_0s.png)
mybatis使用foreach查询不出结果也不报错的问题
2023-11-24 22:36:17
![](https://img.aspxhome.com/file/2023/6/60116_0s.png)
android studio2.3如何编译动态库的过程详解
2023-07-11 03:47:48
java调用openoffice将office系列文档转换为PDF的示例方法
2023-11-29 11:42:53
Java中的Object类详细介绍
2023-11-23 23:18:46
Gradle的安装和环境变量的配置详解
2023-07-11 04:56:37
![](https://img.aspxhome.com/file/2023/2/83552_0s.png)
Java内存区域和内存模型讲解
2023-11-26 12:08:39
![](https://img.aspxhome.com/file/2023/0/59970_0s.png)
jQuery.event.trigger()的简单解释
2023-05-24 03:41:37
![](https://img.aspxhome.com/file/2023/2/62232_0s.png)
java 中sendredirect()和forward()方法的区别
2021-11-07 18:39:28
idea启动springmvc项目时报找不到类的解决方法
2023-11-09 16:51:04
![](https://img.aspxhome.com/file/2023/6/59416_0s.png)
基于Mybatis plus 自动代码生成器的实现代码
2023-11-24 10:40:51
关于@ConditionalOnProperty的作用及用法说明
2023-11-24 02:39:19
SpringMvc框架的简介与执行流程详解
2022-10-15 18:49:00
![](https://img.aspxhome.com/file/2023/4/62354_0s.jpg)
Java泛型定义与用法实例详解
2023-11-25 11:50:28
实例解析Json反序列化之ObjectMapper(自定义实现反序列化方法)
2023-11-23 18:07:25
Java流程控制语句最全汇总(中篇)
2023-11-10 23:52:50
![](https://img.aspxhome.com/file/2023/9/58849_0s.jpg)
SpringCloud Gateway HttpWebHandlerAdapter链路调用请求流程介绍
2023-04-29 00:12:18
![](https://img.aspxhome.com/file/2023/0/61800_0s.png)