• Post Reply Bookmark Topic Watch Topic
  • New Topic

Help on switch  RSS feed

 
Ranch Hand
Posts: 106
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there i have this


I read a file with



then i want for every char to replace it with a digit see below. Example


but it only returns me the first char of every word i send correct output Hello=90888 and i have only 9 what do i do wrong?




thanks

 
author & internet detective
Marshal
Posts: 37518
554
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You don't say what the error is, but I think it is that you don't have a default value. What happens if i pass in the char 'y'? digit would be undefined and that's a problem for Java.
 
Ranch Hand
Posts: 789
C++ Linux Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the input was literally "Hello" you would only match the first letter because you're only comparing upper case. Convert the char to upper case before you use it. If that doesn't work print out what bFile.length is in your for loop.

 
Georgios Chatziefstratiou
Ranch Hand
Posts: 106
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jeanne Boyarsky wrote:You don't say what the error is, but I think it is that you don't have a default value. What happens if i pass in the char 'y'? digit would be undefined and that's a problem for Java.



I don't get error i get only the first letter of the word replaced by a digit not all the words .
 
Georgios Chatziefstratiou
Ranch Hand
Posts: 106
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Guillermo Ishi wrote:If the input was literally "Hello" you would only match the first letter because you're only comparing upper case. Convert the char to upper case before you use it. If that doesn't work print out what bFile.length is in your for loop.



Yes you are right !I have forgot that.
thanks
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!