desislava_topuzakova

03. Sum Numbers

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