标签:string microsoft += format style port info class png
代码:
1 import java.util.*;
2 public class Main {
3 public static void main (String [] args) {
4 int repeat,n;
5 Scanner s=new Scanner(System.in);
6 repeat=s.nextInt();
7 for(int i=1;i<=repeat;i++) {
8 n=s.nextInt();
9 double sum=0;
10 for(int j=1;j<=n;j++) {
11 sum+=1.0/j;
12 }
13 System.out.println(String.format("%.2f", sum));
14 }
15 }
16 }
输入一个正整数repeat,做repeat次下列运算:读入1个正整数n(n<=100),计算并输出1+1/2+1/3+.....+1/n。
标签:string microsoft += format style port info class png
原文地址:https://www.cnblogs.com/fandehui/p/11042335.html