We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
importjava.io.*;importjava.util.*;importjava.math.BigInteger;publicclassSolution{publicstaticvoidmain(String[]args){Scanners=newScanner(System.in);inttestcases=s.nextInt();// Number of test casesBigIntegersum=BigInteger.ZERO;// Summing up all the large numbersfor(inti=0;i<testcases;i++){Stringnum=s.next();// Read the number as a stringsum=sum.add(newBigInteger(num));// Add to the sum using BigInteger}// Convert the sum to a string and print the first 10 digitsStringresult=sum.toString();System.out.println(result.substring(0,10));}}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
An unexpected error occurred. Please try reloading the page. If problem persists, please contact support@hackerrank.com
Project Euler #13: Large sum
You are viewing a single comment's thread. Return to all comments →
Java8 code