primer

13
0
2

Kool: Tallinna Tehnikaülikool (TalTech, TTÜ)

Aine: ICD0019

Kategooria: Informaatika

Postitatud: 29 aprill 2026

Postitaja: ToreHirv


Kirjeldus

Count the number of xx in the given string. We'll say that overlapping is allowed so xxx contains 2 xx. countXX(abcxx) 1 countXX(xxx) 2 countXX(xxxx) 3 int countXX(String str) int count 0 for (int i 0 i str.length()-1 i) if (str.substring(i i2).equals(xx)) count return count Given a string and a non-negative int n we'll say that the front of the string is the first 3 chars or whatever is there if the string is less than length 3. Return n copies of the front frontTimes(Chocolate 2) ChoCho frontTimes(Chocolate 3) ChoChoCho frontTimes(Abc 3) AbcAbcAbc public String frontTimes(String str int n) int frontLen 3 if (frontLen str.length()) frontLen str.length() String front str.substring(0 frontLen) String result for (int i0 in i) result result front return result Given a string return true if the first instance of x in the string is immediately followed by another x. doubleX(axxbb) true doubleX(axaxax) false doubleX(xxxxx) true no9(1 2 19) 1 …