Advertisement
Azazavr

com.javarush.test.level04.lesson16.home03

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