galinyotsev123

ProgBasicsJavaBook5.1Loops04SumNumbers

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