HDOJ 1001Sum Problem

简介: 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.

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();
  }
  }

}
目录
相关文章
HDOJ 2058 The sum problem
HDOJ 2058 The sum problem
107 0
HDOJ 1001Sum Problem
HDOJ 1001Sum Problem
105 0
HDOJ 1002 A + B Problem II
HDOJ 1002 A + B Problem II
113 0
HDOJ 2101 A + B Problem Too
HDOJ 2101 A + B Problem Too
100 0
|
Java
HDOJ 1000 A + B Problem
HDOJ 1000 A + B Problem
107 0
|
Java 文件存储
HDOJ(HDU) 2132 An easy problem
HDOJ(HDU) 2132 An easy problem
100 0
|
Java 文件存储
HDOJ(HDU) 2123 An easy problem(简单题...)
HDOJ(HDU) 2123 An easy problem(简单题...)
150 0
HDOJ1002题A + B Problem II,2个大数相加
HDOJ1002题A + B Problem II,2个大数相加
109 0
HDOJ 2055 An easy problem
HDOJ 2055 An easy problem
104 0
HDOJ(HDU) 1673 Optimal Parking
HDOJ(HDU) 1673 Optimal Parking
119 0