题解 | #等差数列#

等差数列

http://www.nowcoder.com/practice/f792cb014ed0474fb8f53389e7d9c07f

此题过于为简单题,读代码即可读懂。

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while(sc.hasNextInt()) {
            int n = sc.nextInt();
            int count = -1; // 记录当前的值
            int sum = 0; // 记录总和
            for(int i=0; i<n; i++) {
                count += 3;
                sum += count;
            }
            System.out.println(sum);
        }
    }
}
全部评论

相关推荐

牛客84809583...:举报了
点赞 评论 收藏
分享
每晚夜里独自颤抖:要求太多的没必要理
点赞 评论 收藏
分享
评论
5
2
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务