Advertisement
veronikaaa86

03. Exact Sum of Real Numbers

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