Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes Beginning Java and the fly likes if inside for method wont work?!? why? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "if inside for method wont work?!? why?" Watch "if inside for method wont work?!? why?" New topic
Author

if inside for method wont work?!? why?

Dmitri Makovetskiy
Ranch Hand

Joined: Jun 21, 2010
Posts: 128






my goal is to find how many times a character repeatself in the sentence.. but it fails to trigger the if method correctly. why.?
Tom Reilly
Rancher

Joined: Jun 01, 2010
Posts: 618
You if statement is working fine. In your loop you are assigning number2 to number + 1 but number is always zero so number2 is always set to 1. I think you meant
Dmitri Makovetskiy
Ranch Hand

Joined: Jun 21, 2010
Posts: 128
Tom Reilly wrote:You if statement is working fine. Every time through your loop you are assigning number2 to number + 1 but number is always zero so number2 is always set to 1. I think you meant



Tom . thank you. you found my mistake, i wasnt very smart was i...xD
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: if inside for method wont work?!? why?