desislava_topuzakova

03. Sum Numbers

May 8th, 2021
745
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.56 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class SumNumbers_03 {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         int n = Integer.parseInt(scanner.nextLine());
  7.  
  8.         //повтаряме: четем число -> сумираме
  9.         //спираме: сума >= n
  10.         //продължаваме: сума < n
  11.  
  12.         int sum = 0;
  13.         while(sum < n) {
  14.             int number = Integer.parseInt(scanner.nextLine());
  15.             sum += number;
  16.         }
  17.  
  18.         System.out.println(sum);
  19.  
  20.  
  21.     }
  22. }
Advertisement
Add Comment
Please, Sign In to add comment