How many iterations for each loop where max = 10 and incr = 3?

• November 25th, 2013, 02:50 PM
Eli
How many iterations for each loop where max = 10 and incr = 3?
Anybody know how to do this?

How many iterations for each loop where max = 10 and incr = 3?

a) for (int i = 0; i < max; i++)
b) for (int i = 0; i < max; i += 2)
c) for (int i = 0; i < max; i += incr)
d) for (int i = incr; i < max; i += incr)
e) for (int i = max; i > 0; i--)
f) for (int i = max; i < 0; i--)
g) for (int i = 1; i < max; i *= incr)
h) for (int i = 0; i < max; i *= incr)
• November 25th, 2013, 03:07 PM
Norm
Re: How many iterations for each loop where max = 10 and incr = 3?
What have you tried? Write a test program that does what you are asking about, compile and execute it.
If you have any error messages, copy the full text and paste it here.
Also post the code and be sure to wrap the code in code tags:

[code=java]
[/code]
to get highlighting and preserve formatting.
• November 25th, 2013, 03:29 PM
Eli
Re: How many iterations for each loop where max = 10 and incr = 3?
This is what I have but what I don't understand is would I type in the max number as 10 each time?
Code java:

```System.out.print("Please enter the max number:");   int max = input.nextInt(); int i = 0; int total = 0;     for (i = 0; i <=max; i++) { total += i; System.out.println("Number " + i); }```
• November 25th, 2013, 03:36 PM
Norm
Re: How many iterations for each loop where max = 10 and incr = 3?
What are the requirements for the code? If the test requires different values of max then that code would allow the user to enter different values.

For testing I'd just hardcode an assignment of 10:
int max = 10; // input.nextInt();