国产xxxx99真实实拍_久久不雅视频_高清韩国a级特黄毛片_嗯老师别我我受不了了小说

資訊專欄INFORMATION COLUMN

[HackerRank] Simple Array Sum | A Very Big Sum

harriszh / 2801人閱讀

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);
    }
}

文章版權歸作者所有,未經允許請勿轉載,若此文章存在違規行為,您可以聯系管理員刪除。

轉載請注明本文地址:http://specialneedsforspecialkids.com/yun/66020.html

相關文章

  • [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版

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

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

    摘要:這是我在平時有時間的時候做的一些算法上的題目想看更新請移步這里題目描述解法這個問題當時拿到的時候是完全沒有思路的,后面上網查詢了一下這個題目,知道了使用斐波那契數列就能夠解這道題目,,,當然百度作業幫上面也有相應的解法,套路就是題目為一 這是我在平時有時間的時候做的一些算法上的題目 想看更新請移步這里 題目: 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

發表評論

0條評論

harriszh

|高級講師

TA的文章

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