Advertisement
veronikaaa86

03. Sum Numbers

Jun 4th, 2022
237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.51 KB | None | 0 0
  1. package whileLoop;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class P03SumNumbers {
  6. public static void main(String[] args) {
  7. Scanner scanner = new Scanner(System.in);
  8.  
  9. int num = Integer.parseInt(scanner.nextLine());
  10.  
  11. int sum = 0;
  12. while (sum < num) {
  13. int currentNum = Integer.parseInt(scanner.nextLine());
  14. sum += currentNum;
  15.  
  16. // if (sum >= num) {
  17. // break;
  18. // }
  19. }
  20.  
  21. System.out.println(sum);
  22. }
  23. }
  24.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement