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

Thread: Please Help me to understand

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

    Post Please Help me to understand

    Can someone explain this code please
    I cant understand what will print out...

    Please note that i dont want to run it on a program, i would like to understand it.

    for (int x=13; x<20; x+=3){
    int z=x-8;
    for (int y=x; y>z; y-=2)
    System.out.print(y+" ");
    System.out.println(x);
    }

    Thanks


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Please Help me to understand

    One help for you to see what the code does is for the code to be properly formatted.
    Also you should always use {}s with for loops and if statements to clearly show what statements are part of the loops and if statements.
    Also Please edit your post and wrap your code with
    [code=java]
    <YOUR CODE HERE>
    [/code]
    to get highlighting and preserve formatting.

    First thing to do would be to compile and execute the code and see what it prints out.
    Execute the code, copy the output and pasted it here so we can see what the code does.

    It's a waste of time talking about what some code could do, when you can execute it and see what it really does.

    For more info, add a println that prints out the value of z after it is given a value.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Member
    Join Date
    Sep 2012
    Posts
    128
    Thanks
    1
    Thanked 14 Times in 14 Posts

    Default Re: Please Help me to understand

    With these unlikely pieces of code, the intention is to teach you to hand-trace.

    Make a table with all the variables and then run through the program manually.

Similar Threads

  1. Please help to Understand x=++x+ + +x+x++
    By rayan2004 in forum What's Wrong With My Code?
    Replies: 8
    Last Post: December 2nd, 2012, 07:47 PM
  2. Help me to understand this
    By Madhushan in forum Java Theory & Questions
    Replies: 2
    Last Post: September 10th, 2011, 08:47 AM
  3. I can't understand the error.
    By Shivam24 in forum What's Wrong With My Code?
    Replies: 6
    Last Post: July 21st, 2011, 01:56 PM
  4. I dont understand why this happens....
    By ashenwolf in forum What's Wrong With My Code?
    Replies: 4
    Last Post: May 10th, 2011, 09:31 PM
  5. Can't understand why Interfaces are there
    By vortexnl in forum Object Oriented Programming
    Replies: 9
    Last Post: February 14th, 2011, 01:06 PM

Tags for this Thread