Advertisement
Spocoman

07. Sum Numbers

Aug 27th, 2024 (edited)
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.80 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class SumNumbers {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         int n = Integer.parseInt(scanner.nextLine());
  7.         int sum = 0;
  8.  
  9.         for (int i = 0; i < n; i++) {
  10.             int number = Integer.parseInt(scanner.nextLine());
  11.             sum += number;
  12.         }
  13.  
  14.         System.out.println(sum);
  15.     }
  16. }
  17.  
  18. ИЛИ:
  19.  
  20. import java.util.Scanner;
  21.  
  22. public class SumNumbers {
  23.     public static void main(String[] args) {
  24.         Scanner scanner = new Scanner(System.in);
  25.         int n = Integer.parseInt(scanner.nextLine());
  26.         int sum = 0;
  27.  
  28.         for (int i = 0; i < n; i++) {
  29.             sum += Integer.parseInt(scanner.nextLine());
  30.         }
  31.  
  32.         System.out.println(sum);
  33.     }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement