Question
Jave ) While Loop: Count from N to M but quit if multiple of 7 is encountered. Write a program that increments an integer input,
Jave ) While Loop: Count from N to M but quit if multiple of 7 is encountered.
Write a program that increments an integer input, n, to m, but breaks away if the increment ever becomes a multiple of 7. Assume an integer named n is already defined for you and use that to increment. Additionally, assume an integer m is already defined for you, which will act as your limit to increment towards (note: you should be able to increment up to m, but not past it). Store the number of times that you loop through into an integer variable called count, which is also already defined, but not initialized. Examples: - If n = 8 and m = 20, the total number of loops will be 6 (since we encounter 14 along the way). - If n = -6 and m = 12, the total number of loops will be 14 (since we encounter 7 along the way). - If n = 9 and m = 10, the total number of loops will be 1 (since we get to m without encountering any multiples of 7). Note that 0 should not be a valid multiple of 7 at any point in your iterations.
1
int count;
2
// TO-DO: Add your code here (use a do-while loop).
3
// Increment n for each loop that is not a multiple of 7 all the way to m.
4
// Increment count for each time you loop through.
5
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started