aneliabogeva

ExactSumOfRealNumbers

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