Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Turning first word in scentence toUpperCase(nextWord.charAt(0)). Help?  RSS feed

 
tor-einar frostad
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I've been trying for several hours now... Can't get this line of code to work. It prints nextWord as it would without the code. It compiles just fine and my blueJ debugger leaves me with no clue.





Heres my whole for-loop:

 
Campbell Ritchie
Marshal
Posts: 55681
162
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

What you are doing is setting an element in a List (why the + 1?), then printing nextWord. Now, if nextWord is a String, then it cannot change. Rather than printing nextWord, print the List and see what happens.
 
tor-einar frostad
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:Welcome to the Ranch

What you are doing is setting an element in a List (why the + 1?), then printing nextWord. Now, if nextWord is a String, then it cannot change. Rather than printing nextWord, print the List and see what happens.


Thanks!
The +1 one is there because the integer I want to replace is the one after the the int index, wich contains() the characters "!", "." and "?". String nextWord = myList.get(i+1). The variable is declared inside the for-loop. So it should work, right??
 
Knute Snortum
Sheriff
Posts: 4073
112
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You set nextWord in line 3 then without changing it, you print it in line 7. Is this what you expected?
 
tor-einar frostad
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Knute Snortum wrote:You set nextWord in line 3 then without changing it, you print it in line 7. Is this what you expected?



Guess it didn't work because the variable doesn't change with the index given to it. I thought it did. I would have to declare it again before printing it. It worked when I checked my list. Thank you
 
Campbell Ritchie
Marshal
Posts: 55681
162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well done
 
Guillermo Ishi
Ranch Hand
Posts: 789
C++ Linux Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you break it up on different lines instead of chaining functions together you will have better luck with the debuggers I'm familiar with. No reason to not be able to debug it.
 
Campbell Ritchie
Marshal
Posts: 55681
162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Guillermo Ishi wrote:. . . No reason to not be able to debug it.
There might be; OP said he was using BlueJ


You may get the impression I don't like BlueJ. That would be correct.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!