关闭

HDU 1001

标签: acm
257人阅读 评论(0) 收藏 举报
分类:

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 = sum + i;
           }    
    System.out.println(sum);
    System.out.println( );
  /*  if(n==0)
                break;*/
    }
  }
}
0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:29575次
    • 积分:2813
    • 等级:
    • 排名:第12902名
    • 原创:262篇
    • 转载:2篇
    • 译文:0篇
    • 评论:8条