Advertisement
veronikaaa86

03. Exact Sum of Real Numbers

Jan 18th, 2023
1,010
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.53 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 num = Integer.parseInt(scanner.nextLine());
  11.  
  12.         BigDecimal sum = new BigDecimal(0);
  13.         for (int i = 0; i < num; i++) {
  14.             BigDecimal currentNum = new BigDecimal(scanner.nextLine());
  15.  
  16.             sum = sum.add(currentNum);
  17.         }
  18.  
  19.         System.out.println(sum);
  20.     }
  21. }
  22.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement