前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >杭电oj: 1001 Sum Problem java实现

杭电oj: 1001 Sum Problem java实现

作者头像
静谧星空TEL
发布2021-04-27 09:39:13
5830
发布2021-04-27 09:39:13
举报
文章被收录于专栏:云计算与大数据技术

杭电:1001 Sum Problem java实现

Sum Problem

Time Limit: 1000/500 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 623141    Accepted Submission(s): 157688

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

Recommend

We have carefully selected several similar problems for you:  1002 1090 1003 1091 1004

Sum Problem

Time Limit: 1000/500 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 623141    Accepted Submission(s): 157688

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

Recommend

We have carefully selected several similar problems for you:  1002 1090 1003 1091 1004

代码语言:javascript
复制
import java.util.Scanner;

public class Main {
	
	private static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
	
	while(sc.hasNextInt()) {
		int a = sc.nextInt();
		int sum = 0;
		for(int i=1;i<=a;i++) {
			sum += i;
		}
		System.out.println(sum);
		System.out.println();
		}
	}
}
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2019/04/21 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 杭电:1001 Sum Problem java实现
  • Sum Problem
  • Sum Problem
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档