Write a program which takes array of numbers until user inputs 0 and adds them | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Write a program which takes array of numbers until user inputs 0 and adds them

A program which will ask user to enter numbers and to stop they will need to type 0 The problem i cant use scanner since I don't know when the quantity of numbers the user will input. Arraylist allows arrays to expand dynamically as user inputs but I have no clue how it works practically. Any small example will be appreciated

29th Mar 2019, 8:02 PM
kuku Debbarma
kuku Debbarma - avatar
3 Answers
+ 3
kuku Debbarma The code is right. But it won't work on Sololearn. You have to use an IDE on your PC. (On sololearn you can not input the numbers step by step)
29th Mar 2019, 10:54 PM
Denise Roßberg
Denise Roßberg - avatar
+ 1
It has been quite a long time since I last programmed in Java, but if I remember correctly, you can do something like this: Scanner sc = new Scanner(System.in); int input; while(input != 0) { input = sc.nextInt(); }
29th Mar 2019, 8:37 PM
Jan Štěch
Jan Štěch - avatar
+ 1
Thank you for your response I will give it a try at morning!
29th Mar 2019, 9:01 PM
kuku Debbarma
kuku Debbarma - avatar