skipter

for - Calculating nums with for loops

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