Wednesday, 15 July 2015

java - im trying to get the index of a character using only the charAt and length methods for strings -


I am trying to get an index of letters, only four art and long ways to use stars. This is the same question that asks: Declare a public law, which takes a character parameter named Indexof and gives the indicator in the stored string of the first occurrence of that character -1 or if the character is not found. This is what I have to do.

  public int indexOf (char c) {for (i = 0; i & lt; string.length - 1; i ++) {if (string.charAt (c) == string .charAt (i)) {return i; Other {return -1; }}  

You to loop 0 to length () - 1 , and test the value parity of charAt (index) with the given character


No comments:

Post a Comment