亚洲中字慕日产2020,大陆极品少妇内射AAAAAA,无码av大香线蕉伊人久久,久久精品国产亚洲av麻豆网站

資訊專欄INFORMATION COLUMN

[HackerRank] Simple Array Sum | A Very Big Sum

harriszh / 2847人閱讀

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)允許請勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。

轉(zhuǎn)載請注明本文地址:http://www.ezyhdfw.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 評論0 收藏0
  • 劍指offer--JavaScript版

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

    MarvinZhang 評論0 收藏0
  • 一些做著玩的題

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

    cheukyin 評論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 評論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 評論0 收藏0

發(fā)表評論

0條評論

harriszh

|高級講師

TA的文章

閱讀更多
最新活動
閱讀需要支付1元查看
<