• Post Reply Bookmark Topic Watch Topic
  • New Topic

Print string if even ASCII values of characters are before odd ones  RSS feed

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am really struggling with this.
For instance: "bdfce" shall be printed as ASCII values of b d f c e chars are 98 100 102 99 101, so all even ones are in order before odd ones.

This is my attempt and it is not working, I can't seem to spot where the issue is.

 
Sheriff
Posts: 4294
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This will add to finalStr only if the first character is even and the second odd.  What happens in all other cases?
When will finalStr ever be equal to word?
 
Milan Milanovic
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Knute Snortum wrote: This will add to finalStr only if the first character is even and the second odd.  What happens in all other cases?
When will finalStr ever be equal to word?


Should not the if clause check all character as it is inside for loops.
Correct me if I am wrong.
 
Milan Milanovic
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Milan Milanovic wrote:
Knute Snortum wrote: This will add to finalStr only if the first character is even and the second odd.  What happens in all other cases?
When will finalStr ever be equal to word?


Should not the if clause check all character as it is inside for loops.
Correct me if I am wrong.


I see what you mean, how should I fix this?
 
Knute Snortum
Sheriff
Posts: 4294
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, I would think that if need all the "even" letters first and then the "odd" letters, I would add add the ASCII for the even letters to the front of the String and the ASCII for the odd letters to the back of the String. 
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!