码迷,mamicode.com
首页 > 其他好文 > 详细

入门训练 序列求和

时间:2016-11-05 23:42:42      阅读:222      评论:0      收藏:0      [点我收藏+]

标签:span   exti   训练   stat   color   style   com   auto   margin   

技术分享

技术分享

--------------------------------------------------------------------------------------------------------------------------------------

本题很简单主要考察的是对int long类型的限制问题

--------------------------------------------------------------------------------------------------------------------------------------

算法

import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        int n = new Scanner(System.in).nextInt();
        System.out.println((long)n*(n+1)/2);
    }
}

 

--------------------------------------------------------------------------------------------------------------------------------------

int 长度限制是10位

long 长度限制是19位

 

入门训练 序列求和

标签:span   exti   训练   stat   color   style   com   auto   margin   

原文地址:http://www.cnblogs.com/loveluking/p/6034245.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!