Advertisement
Spocoman

03. Exact Sum of Real Numbers

Oct 17th, 2024
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.43 KB | None | 0 0
  1. import java.util.Scanner;
  2. import java.math.BigDecimal;
  3.  
  4. class Main {
  5.     public static void main(String[] args) {
  6.         Scanner scanner = new Scanner(System.in);
  7.         int n = Integer.parseInt(scanner.nextLine());
  8.         BigDecimal sum = new BigDecimal("0");
  9.        
  10.         for (int i = 0; i < n; i++) {
  11.             sum = sum.add(new BigDecimal(scanner.nextLine()));
  12.         }
  13.  
  14.         System.out.println(sum);
  15.     }
  16. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement