解题思路:
注意事项:用java写这题的难题就是小数点,用DecimalFormat方法解决,如代码。
参考代码:
import java.text.DecimalFormat;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc =new Scanner (System.in);
int a =sc.nextInt();
int b =sc.nextInt();
int c =sc.nextInt();
double Sn=0;
for(int i=1;i<=a;i++){
Sn += i;
}
for(int i=1;i<=b;i++){
Sn += i*i;
}
for(int i=1;i<=c;i++){
Sn +=(double)1/i;
}
DecimalFormat decfmt = new DecimalFormat("##0.00");
System.out.println(decfmt.format(Sn));
}
}
0.0分
0 人评分
震宇大神的杀毒软件 (C++代码)浏览:1115 |
求圆的面积 (C语言代码)浏览:1267 |
C语言程序设计教程(第三版)课后习题5.6 (C语言代码)浏览:501 |
P1001 (C语言代码)浏览:800 |
C语言程序设计教程(第三版)课后习题7.4 (C语言代码)浏览:1233 |
2004年秋浙江省计算机等级考试二级C 编程题(1) (C语言代码)浏览:500 |
2005年春浙江省计算机等级考试二级C 编程题(2) (C语言代码)浏览:647 |
最小公倍数 (C语言代码)浏览:1026 |
水仙花 (C语言代码)浏览:1047 |
C语言程序设计教程(第三版)课后习题1.5 (C语言代码)浏览:519 |