• Post Reply Bookmark Topic Watch Topic
  • New Topic

increment array values  RSS feed

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
I'm attempting to increment the values by 1 in an array of objects but I'm not able to increment with the increment operator.



It just loops the value of hour without incrementing.
Can anyone help?
Thanks,
 
Sheriff
Posts: 4289
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What's the difference between i++ and ++i? And do you want to use an incrementer like that?

And is minute spelled correctly?

And what's happening to the value of a[i].getHour()?
 
Bartender
Posts: 1445
30
C++ Java Netbeans IDE Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That doesn't quite look like real code, Greg. Can you post your actual program?
 
Greg Murphy
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
Thank you all for offering to help and
responding so quickly.
After I posted this I figured it out.
I needed to ++i on the object's parameters
before
they were sent to the constructor.
I was trying to increment them after I passed
the constructed object's values to an array.
 
Ranch Hand
Posts: 71
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch.
 
Stevens Miller
Bartender
Posts: 1445
30
C++ Java Netbeans IDE Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Greg Murphy wrote:
After I posted this I figured it out.

It's amazing, how often this happens.
 
Marshal
Posts: 56600
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch (again)
I have added code tags to your post and a final }. Always use the code tags; don't they make it look better . Unfortunately you have a style error we see rarely: two statements per line in that loop. That makes the code difficult to read. you should always copy and paste code onto the forum: that should obviate any spellling problems.

Lots of people fall into the pitfall of thinking that i = i++; actually changes anything. If there is any risk of confusion, you might do well to restrcit yourself to i++; and have that as the whole statement. You then put it before or after the line you want to use i on.
Another thing: you are writing getHour() but not using that hour return value directly. Whatever came from your getXXX calls simply vanished into cyber‑limbo never to be seen again.
 
Campbell Ritchie
Marshal
Posts: 56600
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have found some old posts about i = i++; which might be useful to read: 1 with links to 2 and 3, 4 5. So frequent is this question that we have an FAQ about it.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!