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 7 of 7

Thread: excuse me, can somebody explain how this constructor work? thanks before

  1. #1
    Banned
    Join Date
    Apr 2012
    Posts
    38
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default excuse me, can somebody explain how this constructor work? thanks before

    void tampil(){
    for(i=0;i<=20;i++)
    {
    System.out.print(i+" ");
    if(i%2==1)
    {
    System.out.print(i+" ");
    }
    }
    }


  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: excuse me, can somebody explain how this constructor work? thanks before

    Which statement are you asking about? What happens when the code is executed? The output will show you what the code does when it is executed?

    The % 2 == 1 test could be used to determine if a number is odd
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Banned
    Join Date
    Apr 2012
    Posts
    38
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: excuse me, can somebody explain how this constructor work? thanks before

    Quote Originally Posted by Norm View Post
    Which statement are you asking about? What happens when the code is executed? The output will show you what the code does when it is executed?

    The % 2 == 1 test could be used to determine if a number is odd
    i mean how constructor for(i=0;i<=20;i++) can join with constructor if(i%2==1), how the process ? why can produce output 0 11 22 33 until 20?

  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: excuse me, can somebody explain how this constructor work? thanks before

    Please post the output from when you execute the program.
    If you don't understand my answer, don't ignore it, ask a question.

  5. The Following User Says Thank You to Norm For This Useful Post:

    erdy_rezki (April 19th, 2012)

  6. #5
    Junior Member
    Join Date
    Sep 2011
    Location
    IN
    Posts
    14
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Thumbs up Re: excuse me, can somebody explain how this constructor work? thanks before

    Quote Originally Posted by erdy_rezki View Post
    void tampil(){
    for(i=0;i<=20;i++)
    {
    System.out.print(i+" ");
    if(i%2==1)
    {
    System.out.print(i+" ");
    }
    }
    }
    Hello,

    i initialize with 0 so first print 0 then

    its comes next if statement it checks with i value

    if its odd means it will give 1

    otherwise 0

    so only odd no's print twice...

    Check with your output and keep rocking....

  7. The Following User Says Thank You to treacyjane For This Useful Post:

    erdy_rezki (April 19th, 2012)

  8. #6
    Banned
    Join Date
    Apr 2012
    Posts
    38
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: excuse me, can somebody explain how this constructor work? thanks before

    Quote Originally Posted by Norm View Post
    Please post the output from when you execute the program.
    the output is 0 11 2 33 4 55 6 77 8 99 10 11 11 12 13 13 14 15 15 16 17 17 18 19 19 20

  9. #7
    Banned
    Join Date
    Apr 2012
    Posts
    38
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: excuse me, can somebody explain how this constructor work? thanks before

    Quote Originally Posted by treacyjane View Post
    Hello,

    i initialize with 0 so first print 0 then

    its comes next if statement it checks with i value

    if its odd means it will give 1

    otherwise 0

    so only odd no's print twice...

    Check with your output and keep rocking....
    oke thanks for your comment it really help

Similar Threads

  1. i need an explain please !
    By keep smiling in forum Java Theory & Questions
    Replies: 3
    Last Post: December 21st, 2011, 11:22 AM
  2. Could you explain this code to me please?
    By TP-Oreilly in forum Java Theory & Questions
    Replies: 8
    Last Post: December 7th, 2011, 02:10 PM
  3. Replies: 1
    Last Post: December 13th, 2010, 05:13 AM
  4. Can anyone explain this code for me
    By gudwindavids in forum Object Oriented Programming
    Replies: 1
    Last Post: December 11th, 2009, 02:29 PM
  5. can anyone explain this?
    By chronoz13 in forum Java Theory & Questions
    Replies: 4
    Last Post: October 12th, 2009, 02:51 AM