• Post Reply Bookmark Topic Watch Topic
  • New Topic

for-loop question  RSS feed

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
please i need explanation. how did the answer arrived at 024


 
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please post real code. That code snippet fails to compile because of the jj - in the condition. Did you mean jj - 1? If so, the answer is simple. Just write down for each iteration what the value of ii and jj are, and run through the program in your head.
 
Bartender
Posts: 1664
37
Eclipse IDE Google Web Toolkit Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, You can post your questions in the Beginning java forum which is suited towards answering such questions.
Your code does not compile, maybe you meant something else ?
 
Sheriff
Posts: 11494
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My guess is that it's jj--, which would result in the output that OP is asking about.
 
Junilu Lacar
Sheriff
Posts: 11494
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@OP: To understand why you are getting the output you are seeing, you need to learn how to manually trace though the code and follow along with its execution.

This table can help:

iijjii < jj--output
07true"0"
????
????
????


I did the first row for you. Try to complete the next three rows.

Edit: Seems like the output would be the same if it was ii < jj - 1

In that case, try to fill in this table:


iijj - 1ii < jj - 1output
06true"0"
????
????
????


Try to figure this out for yourself first. You'll get more help from folks here if you Show Some Effort
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!