Project Euler #13: Large sum

Hacker Rank Question

Solution


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
import java.util.*;
import java.math.*;

public class Solution {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();

        BigInteger sum = new BigInteger("0");
        for (int i = 0; i < n; i++){
            String s = sc.next();
            BigInteger bi = new BigInteger(s);
            sum = sum.add(bi);
        }
        System.out.println(String.valueOf(sum).substring(0, 10));
    }
}

Comments

Popular Posts