Results 1 to 14 of 14

Thread: Basic loops

  1. #1
    Samari413 is offline Member
    Join Date
    Nov 2010
    Posts
    5
    Rep Power
    0

    Question Basic loops

    I want this (-) to appear next to each other 30 times...Why isnt this happening? i don't understand loops!!:confused:

    Java Code:
         for (int i=0; i<=30; i++)
             {
             
                System.out.println( '-' );
             
             }

  2. #2
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,573
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by Samari413 View Post
    I want this (-) to appear next to each other 30 times...Why isnt this happening? i don't understand loops!!:confused:

    Java Code:
         for (int i=0; i<=30; i++)
             {
             
                System.out.println( '-' );
             
             }
    Use System.out.print( ... ) instead; System.out.println( ... ) prints a newline after it has printed its argument. It has nothing to do with loops.

    kind regards,

    Jos

  3. #3
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,049
    Rep Power
    20

    Default

    That code will print more than 30 times currently...

  4. #4
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

  5. #5
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,049
    Rep Power
    20

    Default

    That could be the one that brings about the Apocalypse, though!

  6. #6
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Could be.

    But I'm really confusing over here, "(-) to appear next to each other 30 times". How can we do this.

  7. #7
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,573
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by Eranga View Post
    Could be.

    But I'm really confusing over here, "(-) to appear next to each other 30 times". How can we do this.
    No need to be confused; I already gave the answer but of course my replies are ignored; as always ;-)

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  8. #8
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,049
    Rep Power
    20

    Default

    No, I suspect the OP has taken your code and left...without even looking back.

  9. #9
    venerik is offline Member
    Join Date
    Oct 2010
    Posts
    94
    Rep Power
    0

    Default

    So Samari413 took JosAH's invaluable intellectual property and is getting rich of it somewhere...

    :)
    I'm new to Java but I like to help where ever I can. :)

  10. #10
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,049
    Rep Power
    20

    Default

    Yep.
    I can hear the cash registers from here.

  11. #11
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,573
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by venerik View Post
    So Samari413 took JosAH's invaluable intellectual property and is getting rich of it somewhere...

    :)
    Dang, while I only charge euro 0.25 for every System.out.println( ... ) used (a System.out.print( ... ) only costs euro 0.20 per use) That darn scrooge ... that costs me euro 0.20 ... while I just wanted to be filthy rich and surrounded by scantily clad women all day and have lots of Grolsch available at the snap of my fingers ...

    kind regards,

    Jos (<--- poor old sod ;-)
    cenosillicaphobia: the fear for an empty beer glass

  12. #12
    al_Marshy_1981 is offline Senior Member
    Join Date
    Feb 2010
    Location
    Waterford, Ireland
    Posts
    748
    Rep Power
    5

    Default

    Quote Originally Posted by JosAH View Post
    Dang, while I only charge euro 0.25 for every System.out.println( ... ) used (a System.out.print( ... ) only costs euro 0.20 per use) That darn scrooge ... that costs me euro 0.20 ... while I just wanted to be filthy rich and surrounded by scantily clad women all day and have lots of Grolsch available at the snap of my fingers ...

    kind regards,

    Jos (<--- poor old sod ;-)
    cries in despair, if Jos is struggling how can a mere mortal make it :D

  13. #13
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Quote Originally Posted by Tolls View Post
    No, I suspect the OP has taken your code and left...without even looking back.
    I agreed with you. I don't think that OP may not looking in depth that code.

  14. #14
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Quote Originally Posted by JosAH View Post
    No need to be confused; I already gave the answer but of course my replies are ignored; as always ;-)

    kind regards,

    Jos
    I don't think Jos. In each replay of yours have something interest to learn. If someone not interest on it, then I'm sure he/she is never learn how to use Java properly. Keep it up yours mate. :)

Similar Threads

  1. Help with loops!
    By jrelvi23 in forum New To Java
    Replies: 9
    Last Post: 09-04-2012, 01:36 PM
  2. While Loops, need a bit of help.
    By Keno777 in forum New To Java
    Replies: 7
    Last Post: 10-30-2009, 08:24 PM
  3. these loops...
    By Blaedel in forum New To Java
    Replies: 0
    Last Post: 10-01-2009, 06:59 PM
  4. how to use do while loops
    By mikeitalydz in forum New To Java
    Replies: 32
    Last Post: 09-26-2009, 08:30 PM
  5. Loops (while do etc)
    By manupr in forum New To Java
    Replies: 1
    Last Post: 01-15-2008, 03:59 AM

Posting Permissions

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