1001:Sum Problem
2012-05-24 19:30
281 查看
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
Sample Output
answer:
注意点:最后一行的空格要写成:\r\n,windows中的空格就是这样!
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
answer:
import java.util.Scanner; public class Main{ public static void main(String[] args) { Scanner scan = new Scanner(System.in); long i,sum,n; while(scan.hasNextLong()) { n = scan.nextLong(); sum = 0; for(i=1; i<=n;i++) { sum = sum+i; } System.out.println(sum); System.out.print("\r\n"); } }
注意点:最后一行的空格要写成:\r\n,windows中的空格就是这样!
相关文章推荐
- hdu 1001 Sum Problem (1+2+3+·······+n=)
- 杭电ACM 1001:Sum Problem
- HDU 1001 Sum Problem(水~)
- HDOJ1001 Sum Problem_C++
- HDU 1001 Sum Problem JAVA
- HODJ 1001 Sum Problem C++解法
- ACM之杭电——1001_Sum Problem
- HODJ 1001 Sum Problem C++解法
- 84.hdu--1001--Sum Problem
- hdoj1001 Sum Problem(细心点)
- hdu 1001 Sum Problem 的解题报告
- JAVA hdu 1000(A + B Problem)&&hdu 1001(Sum Problem)
- hdu1001 Sum Problem 差点被这个题玩死了
- hduoj1001(Sum Problem)
- 杭州电子科技大学 ACM 1001 Sum Problem
- Sum Problem -- hdu acm 1001
- HDU 1001【Sum Problem】
- 从零开始刷HDOJ(2)【HDOJ1001 - Sum Problem】
- hdu 1001 Sum Problem 解题报告 数据范围
- HDOJ 1001 Sum Problem