原创
Sum Problem
Time Limit: 1000/500 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 560410 Accepted Submission(s): 142045
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
Author
DOOM III
此题有个小坑,每一个输入输出案例之间都要有一个空行:
2
3
(空行)
100
5050
Accepted
1 import java.util.*; 2 3 public class HDOJ_1001 { 4 5 public static void main(String[] args) { 6 Scanner reader=new Scanner(System.in); 7 while(reader.hasNext()) { 8 long n=reader.nextInt(); 9 long sum=((1+n)*n)/2;10 System.out.println(sum);11 System.out.println();;12 }13 }14 15 }
12:04:33
2018-08-15