Advertisement
veronikaaa86

03. Exact Sum of Real Numbers

May 25th, 2022
412
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. package dataTypesAndVariables;
  2.  
  3.  
  4. import java.math.BigDecimal;
  5. import java.util.Scanner;
  6.  
  7. public class P03ExactSumOfRealNumbers {
  8. public static void main(String[] args) {
  9. Scanner scanner = new Scanner(System.in);
  10.  
  11. int n = Integer.parseInt(scanner.nextLine());
  12.  
  13. BigDecimal sum = new BigDecimal(0);
  14. for (int i = 0; i < n; i++) {
  15. BigDecimal currentNum = new BigDecimal(scanner.nextLine());
  16.  
  17. sum = sum.add(currentNum);
  18. }
  19.  
  20. System.out.println(sum);
  21.  
  22. }
  23. }
  24.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement