-3

If you get the length of a String using length(), the String always being multiples of 3 (in my case: "1.02.03.04.05.06.07.0 etc.").
Each 3 characters representing a letter, with .1 indicating a capital letter.

How do you use the length to find how many sequences of three there are in the String, for each instance of said String (each time being another multiple of 3)?

Edit:

Yes to Burrito's question, I am looking to find the number of 3 character blocks in each unique String.

Community
  • 1
  • 1
Samuel Finzhry
  • 35
  • 1
  • 10

1 Answers1

1

It's pretty simple. Next time please show the working of your code.

public int findMultiplesOf3(String value)
{
    return (value.length()/3);
}

Edit


Any length of the string which is less than 3 or not divisible by 3, the return value will only be a whole number. (For Ex 22/3 = 7.333 But the return value would be 7) Since we are returning an int (integer) value in the function header.

user3337714
  • 663
  • 1
  • 7
  • 25
  • Your first two return statements are unnecessary. The last line will return the correct result regardless of the length of the input string. – BJ Myers Jun 18 '15 at 04:51
  • 1
    the user should be informed that each fraction will be cut behind the decimal point. there is no rounding when casting to int. – Dude Jun 18 '15 at 06:00