File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to alternate between two sets in a string?

 
Ashley Kin
Ranch Hand
Posts: 36
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying to write a method that accepts a string of names followed by integers, and the names alternate between boys and girls.
For examples: "Mark 41 Jennifer 22 Daniel 49 Jessica 67 Joshua 87"
The output should be:
3 boys, 2 girls
boys sum = 177
girls sum = 89

I'm having trouble just figuring out first of all how to alternate, and then how to get past the names to the integers.
Any help is appreciated, thank you!

 
Harsha Smith
Ranch Hand
Posts: 287
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good Job Ashley, almost there...... check this code. Take another variable 'i'

 
Ashley Kin
Ranch Hand
Posts: 36
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I compile it and it runs without error, but nothing prints out and the run does not end. Is it because the string starts with a name?

This is my complete code right now:


 
Harsha Smith
Ranch Hand
Posts: 287
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
problem is with line 19(remove semicolon), line34(remove it)
 
Ashley Kin
Ranch Hand
Posts: 36
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh wow, I see. Thanks for catching that! My full program works now!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic