HDOJ 1001Sum Problem
发布日期:2021-06-29 13:30:04 浏览次数:2 分类:技术文章

本文共 704 字,大约阅读时间需要 2 分钟。

Problem Description

Hey, welcome to HDOJ(Hangzhou Dianzi University Online Judge).

In this problem, your task is to calculate SUM(n) = 1 + 2 + 3 + … + n.

Input

The input will consist of a series of integers n, one integer per line.

Output

For each case, output SUM(n) in one line, followed by a blank line. You may assume the result will be in the range of 32-bit signed integer.

Sample Input

1
100

Sample Output

1

5050

import java.util.*;class Main{  public static void main(String args[]){    Scanner sc = new Scanner(System.in);    while(sc.hasNext()){      int n = sc.nextInt();      int sum=0;      for(int i=1;i<=n;i++)        sum+=i;      System.out.println(sum);      System.out.println();  }  }}

转载地址:https://chenhx.blog.csdn.net/article/details/49334627 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:HDOJ 1064Financial Management
下一篇:HDOJ 1000 A + B Problem

发表评论

最新留言

做的很好,不错不错
[***.243.131.199]2024年04月06日 04时45分04秒

关于作者

    喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!

推荐文章