Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

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

  1. #1
    Junior Member
    Join Date
    Nov 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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)


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default 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]
    YOUR CODE HERE
    [/code]
    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Nov 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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?
    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);
    		}

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default 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();
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Replies: 2
    Last Post: October 5th, 2012, 01:14 PM
  2. [SOLVED] String max out
    By lorider93p in forum Java Theory & Questions
    Replies: 7
    Last Post: March 2nd, 2012, 10:43 AM
  3. Multi-D array. daily max/min/avg, weekly max/min/avg, sum total (99% done)
    By TheWhopper858 in forum Collections and Generics
    Replies: 1
    Last Post: November 6th, 2011, 08:50 PM
  4. [SOLVED] Problem using the length of a string to bound the number of iterations of a for loop
    By dtitt3 in forum Loops & Control Statements
    Replies: 1
    Last Post: November 3rd, 2011, 01:44 PM
  5. max length of an array?
    By qsbladey in forum Collections and Generics
    Replies: 4
    Last Post: April 3rd, 2011, 11:17 AM

Tags for this Thread