Advertisement
Azazavr

javarush.test.level04.lesson16.home03

Oct 28th, 2016
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.78 KB | None | 0 0
  1. package com.javarush.test.level04.lesson16.home03;
  2.  
  3. import java.io.*;
  4.  
  5. /* Посчитать сумму чисел
  6. Вводить с клавиатуры числа и считать их сумму. Если пользователь ввел -1, вывести на экран сумму и завершить программу.  -1 должно учитываться в сумме.
  7. */
  8.  
  9. public class Solution
  10. {
  11.     public static void main(String[] args)   throws Exception
  12.     {
  13.         BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
  14.  
  15.         int a=0;
  16.         int b=0;
  17.  
  18.         while (a != -1){
  19.             a = Integer.parseInt(reader.readLine());
  20.             if (a != -1)
  21.             b=b+a;
  22.         }
  23.         System.out.println(b-1);
  24.     }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement