package com.codegym.task.task04.task0442;
/*
Adding
*/
import java.io.*;
import java.util.Scanner;
public class Solution {
public static void main(String[] args) throws Exception {
//write your code here
int a = 0;
int sum = 0;
Scanner scan = new Scanner(System.in);
while(true){
a = scan.nextInt();
if(a==-1){
sum--;
System.out.println(sum);
break;
}
sum +=a;
}
}
}
hidden #10463947
Level 7
ANSWER
Under discussion
Comments (5)
- Popular
- New
- Old
You must be signed in to leave a comment
Vladimir Vukdragovic
22 June 2019, 08:29
Thanks it worked
0
Berkson
14 June 2019, 18:19
You can use a do while loop too:
This way you are doing what the question asks.
The same applies to your code.
0
Dharun Karthi
14 June 2019, 16:24
put the operation of 'sum' inside the while loop(but not inside if condition) and the print statement outside the while loop.
0
hidden #10463947
15 June 2019, 13:40
I have finished the task, this is an answer.
0
Dharun Karthi
21 June 2019, 16:25
ok :)
0