成人国产在线小视频_日韩寡妇人妻调教在线播放_色成人www永久在线观看_2018国产精品久久_亚洲欧美高清在线30p_亚洲少妇综合一区_黄色在线播放国产_亚洲另类技巧小说校园_国产主播xx日韩_a级毛片在线免费

資訊專(zhuān)欄INFORMATION COLUMN

[HackerRank] Simple Array Sum | A Very Big Sum

harriszh / 2811人閱讀

Simple Array Sum

Problem

Given an array of N integers, can you find the sum of its elements?

Input Format

The first line contains an integer, N, denoting the size of the array.
The second line contains N space-separated integers representing the array"s elements.

Output Format

Print the sum of the array"s elements as a single integer.

Sample Input

6
1 2 3 4 10 11

Sample Output

31

Solution

import java.io.*;
import java.util.*;

public class Solution {
    public static void main(String[] args) {
        /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
        Scanner sc = new Scanner(System.in);
        int size = sc.nextInt();        
        int sum = 0;

        while(sc.hasNextInt()){          
            sum += sc.nextInt();
        }
        System.out.print(sum);
    }
}
A Very Big Sum

Solution

import java.io.*;
import java.util.*;

public class Solution {

    public static void main(String[] args) {
        /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
        Scanner sc = new Scanner(System.in);
        int size = sc.nextInt();        
        long sum = 0;

        while(sc.hasNextInt()){          
            sum += (long)sc.nextInt();
        }
        System.out.print(sum);
    }
}

文章版權(quán)歸作者所有,未經(jīng)允許請(qǐng)勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。

轉(zhuǎn)載請(qǐng)注明本文地址:http://systransis.cn/yun/66020.html

相關(guān)文章

  • [HackerRank] Diagonal Difference

    Problem Given a square matrix of size N x N, calculate the absolute difference between the sums of its diagonals. Input Format The first line contains a single integer, N. The next N lines denote the ...

    warmcheng 評(píng)論0 收藏0
  • 劍指offer--JavaScript版

    摘要:劍指在一個(gè)二維數(shù)組中,每一行都按照從左到右遞增的順序排序,每一列都按照從上到下遞增的順序排序。例如輸入前序遍歷序列和中序遍歷序列,則重建二叉樹(shù)并返回。其中負(fù)數(shù)用補(bǔ)碼表示。 本文為8月牛客網(wǎng)《劍指 offer》刷題做得,現(xiàn)整理出來(lái)作為參考。雖然是算法題,但本文用 JavaScript 編寫(xiě),看了《劍指 offer》以后發(fā)現(xiàn)很多問(wèn)題處理的過(guò)程并不是最好的,所以本文僅供參考。以前全部代碼 A...

    MarvinZhang 評(píng)論0 收藏0
  • 一些做著玩的題

    摘要:這是我在平時(shí)有時(shí)間的時(shí)候做的一些算法上的題目想看更新請(qǐng)移步這里題目描述解法這個(gè)問(wèn)題當(dāng)時(shí)拿到的時(shí)候是完全沒(méi)有思路的,后面上網(wǎng)查詢了一下這個(gè)題目,知道了使用斐波那契數(shù)列就能夠解這道題目,,,當(dāng)然百度作業(yè)幫上面也有相應(yīng)的解法,套路就是題目為一 這是我在平時(shí)有時(shí)間的時(shí)候做的一些算法上的題目 想看更新請(qǐng)移步這里 題目: Climbing Stairs 描述 You are climbing a ...

    cheukyin 評(píng)論0 收藏0
  • Make a simple custom EventEmitter

    Thoughts Recently I have been reading the book Async Javascript about JS asynchronicity and JS event is one of the useful solutions to the problem. To get a deeper understanding of how events work, I ...

    fizz 評(píng)論0 收藏0
  • You need to know curry

    Functions are first-class citizen Functions are first-class citizen in JavaScript, as the same as other types(e.g. number, array, object). They can be used as arguments, as well as return value from o...

    BigNerdCoding 評(píng)論0 收藏0

發(fā)表評(píng)論

0條評(píng)論

最新活動(dòng)
閱讀需要支付1元查看
<