plamen27

3Exact SumofReal Numbers Java fixed

Sep 27th, 2016
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.51 KB | None | 0 0
  1. package ProgFundamentals;
  2. import java.math.BigDecimal;
  3. import java.util.Scanner;
  4.  
  5. public class OneLabThreeExactSumOfRealNumbers {
  6. public static void main(String[] args){
  7. Scanner sc = new Scanner(System.in);
  8. int n = sc.nextInt();
  9. BigDecimal bigSum = BigDecimal.valueOf(0);
  10.  
  11. while(n>0){
  12. BigDecimal tempNum = sc.nextBigDecimal();
  13. bigSum = bigSum.add(tempNum);
  14. n--;
  15. }
  16. sc.close();
  17. System.out.println(bigSum);
  18. }
  19. }
Add Comment
Please, Sign In to add comment