Results 1 to 4 of 4

Thread: for loop help

  1. #1
    DMarsh12 is offline Member
    Join Date
    Mar 2011
    Posts
    43
    Rep Power
    0

    Default for loop help

    I have an exam tomorrow in class and I am stuck on creating 2 separate for loops

    The first is reproducing even numbers from 2 to 10.

    Here is what I have...

    public class loops {

    public static void main(String[] args)
    {
    for (int i=0; i<=10; i+=2);
    System.out.println(i + "");
    }


    }

    It says there is no variable for i which I don't understand...


    The second loop I have to make is creating a loop that makes a sentence repeat four times which I am completely lost on

    any help is greatly appreciated

  2. #2
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    You have a misplaced semicolon. Also a better approach is to use and if clause and the modulus operator. The second part is basic. Start it and post your best try.

  3. #3
    DMarsh12 is offline Member
    Join Date
    Mar 2011
    Posts
    43
    Rep Power
    0

    Default

    Quote Originally Posted by sunde887 View Post
    You have a misplaced semicolon. Also a better approach is to use and if clause and the modulus operator. The second part is basic. Start it and post your best try.
    thank you very much for that! i was getting very frustrated with this and have figured out the second question thanks to that semicolon issue...i appreciate it

    +rep

  4. #4
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    You're welcome. Please mark your thread solved with the thread tools if you are done. Glad to have helped you. Good luck on your test.

Similar Threads

  1. JTextField loop 2x for-loop WEIRD!
    By Streetproject in forum AWT / Swing
    Replies: 2
    Last Post: 02-16-2011, 06:46 PM
  2. [Q] Loop issue (while loop)
    By iriscience in forum New To Java
    Replies: 9
    Last Post: 01-31-2011, 05:21 PM
  3. Convert do while loop to for loop
    By sandeeptheviper in forum New To Java
    Replies: 3
    Last Post: 01-03-2011, 01:37 PM
  4. Replies: 5
    Last Post: 04-30-2010, 06:05 PM
  5. while-loop stopping on first loop
    By davester in forum New To Java
    Replies: 6
    Last Post: 06-26-2009, 09:46 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •