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):
or it's something to do with using a char here, rather than a String (or something else?).
I'd rather not post my full code publically but any advice or guidance would be fantastic
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






