zoukankan      html  css  js  c++  java
  • Sum Problem

    原创


    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

  • 相关阅读:
    11-Mybatis中使用PageHelper分页插件
    10-Mybatis使用注解开发
    Windows快捷键
    环境搭建
    计算机基础
    oracle语句
    oracle
    测试质量和类型
    测试基础
    项目部署和总结
  • 原文地址:https://www.cnblogs.com/chiweiming/p/9480657.html
Copyright © 2011-2022 走看看