Results 1 to 5 of 5
Thread: Replace String with "*"
- 06-09-2010, 04:36 PM #1
Member
- Join Date
- Apr 2010
- Posts
- 28
- Rep Power
- 0
Replace String with "*"
Say I have the word 'Mississippi'. The program I'm writing basically does asks the user for a number, and if that number is greater than 4, the given word (Mississippi) becomes masked with '*', so in this case, '***********'. But, if the user enters 3, then the given word is only masked up to every fourth letter, so for example, in this case, '***s***i***'. Now, how can I write code to mask in this way (only masking some of the text and not all)? I figured out how to mask them all for 4, that's pretty easy, but should I use a loop for 3? I'm not sure how to begin..
- 06-09-2010, 04:39 PM #2
Senior Member
- Join Date
- Feb 2009
- Posts
- 303
- Rep Power
- 5
I would suggest using a for loop to iterate through all the characters. The % operator would also help.
- 06-09-2010, 04:39 PM #3
Yes, looks like a loop is needed.
Use a paper and pencil to work out the steps need to do the job, Look at how you did it and then design a program to do it.
- 06-09-2010, 04:43 PM #4
Member
- Join Date
- Apr 2010
- Posts
- 28
- Rep Power
- 0
- 06-09-2010, 04:44 PM #5
Similar Threads
-
string comparison with "=" and ".equal"
By guavajuice in forum New To JavaReplies: 9Last Post: 04-22-2010, 09:01 PM -
final String currentWorld = "Java Forums"; String.format("Hello %s", currentWorld);
By mcfrog in forum IntroductionsReplies: 0Last Post: 04-02-2009, 07:02 PM -
MoneyOut.println("It took you (whats wrong?>",year,"<WW?) years to repay the loan")
By soc86 in forum New To JavaReplies: 2Last Post: 01-24-2009, 06:56 PM -
Replace "\" with "/"
By heartysnowy in forum New To JavaReplies: 4Last Post: 11-20-2008, 04:16 AM -
the dollar sign "$", prints like any other normal char in java like "a" or "*" ?
By lse123 in forum New To JavaReplies: 1Last Post: 10-20-2008, 07:35 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks