samedi 28 février 2015

Java: is there an int method like charAt()?

I don't want "charAt(1);" to return the character at position 1 in the string... I want it to report all instances of "matching = 1;"


Take for example



int matching = 1;
int notMatching = 0;
int HI = matching;
int IH = notMatching;
int searchString = theString.charAt(notMatching);

int count = 0;
int index = 0;

while (0 < theString.length())
{
int = theString.charAt(matching);
if (theString.charAt(notMatching) == searchString)
{
count = count + 1;
}
index = index + 1;
}


Not a great example but basically what I want, or what this program is supposed to do is take a user input:



HIHIIH



and report the instances of HI spelled as IH... so the return would be for instance;



System.out.println("HI was spelled as IH" + count + "times");



Aucun commentaire:

Enregistrer un commentaire