Unstoppable Domains โ€” Expired Auctions

Java - Counting certain letters in sentences (spaces cause problems)

SpaceshipSpaceship
Watch

thomase

Established Member
Impact
3
I'm currently doing a Java activity where I need to count how many times a particular letter is used in a sentence.

I have made it all work so that everytime a particular letter shows it counts it. However, it only works when there are no spaces.

I tried to be "clever" and use an str_replace like you get in php (but I barely know how to use it in php and I couldn't get it to work in java).

I think the problem is that this bit which has just had the text inputted via a scanner does not count spaces as part of the length, nor does it count anything after the space (unless the space is the first thing, but it still ignores It):

Code:
//checks len gth of inputted tecxt
int lengthtext = textInputted.length();
System.out.println("lengeth of tect: " + lengthtext);

or it's something to do with using a char here, rather than a String (or something else?).

Code:
//checks letter at particular bit    
char letter = textInputted.charAt(letterpoint);


I'd rather not post my full code publically but any advice or guidance would be fantastic :)
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
.US domains.US domains
Okay, Don't worry! I've sorted out the problem. Error with my scanner :D
 
0
•••
Dynadot โ€” .com TransferDynadot โ€” .com Transfer
Spaceship
Domain Recover
DomainEasy โ€” Payment Flexibility
  • The sidebar remains visible by scrolling at a speed relative to the pageโ€™s height.
Back