For, while, do while | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

For, while, do while

Здравствуйте, только начал знакомиться с программированием.Столкнулся с проблемой связанной с циклами в java.Задание такое: с помощью сканера спросить числа, (a, b) с чем я успешно справился и объявить численный коэффициент можно в консоли, но тут проблема, я не могу сообразить как рассчитать сумму чисел с помощью всех трех циклов.То есть, к примеру я присвоил в консоли буквенному коэффициенту (a) = 1, а (b) = 10 - нужно, чтобы в промежутке этих чисел циклы все суммировали.С тем, как вывести результат на экран я справлюсь, а вот с циклами незадача 🤯

7th Jun 2019, 7:58 AM
Lustforknowledge
Lustforknowledge - avatar
5 Answers
+ 1
I used google translate. If I understand it correct you get two numbers from the user. Can you give an example what you want to do with theese two numbers?
7th Jun 2019, 10:09 AM
Denise Roßberg
Denise Roßberg - avatar
+ 1
If you know the number of cycles I would use a for loop: for(int i = 0; i < 3; i++){ sum = sum + (some coefficient) //short: sum += coefficient } If you need a while loop: int cycles = 3; while(cycles > 0){ sum += some coeffient cycles--; }
7th Jun 2019, 11:03 AM
Denise Roßberg
Denise Roßberg - avatar
+ 1
Thank you!
7th Jun 2019, 11:05 AM
Lustforknowledge
Lustforknowledge - avatar
0
Yes, you got it right. Thanks to the resulting numbers, you need to calculate the sum of the numbers in the gap with the help of three cycles, in one, as far as I know, this is done with the command sum = sum + (some coefficient)
7th Jun 2019, 10:15 AM
Lustforknowledge
Lustforknowledge - avatar
0
Your welcome :) edit: i < 3 (I changed it in the post)
7th Jun 2019, 11:10 AM
Denise Roßberg
Denise Roßberg - avatar