aishwaryaneelakandan / Assignment

1 stars 1 forks source link

task0926 #3

Closed ravi-priya closed 3 years ago

ravi-priya commented 3 years ago

9/26 assignment

Slot 1 write these methods in Compare class( Compare.java) and a few different tests for each in CompareTest.

  1. 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

2.Given an array of ints, return the number of 9's in the array.

arrayCount9([1, 2, 9]) → 1 arrayCount9([1, 9, 9]) → 2 arrayCount9([1, 9, 9, 3, 9]) → 3

3.Given an int n, return the absolute difference between n and 21, except return double the absolute difference if n is over 21.

diff21(19) → 2 diff21(10) → 11 diff21(21) → 0

Slot 2 write these methods in Compare class( Compare.java) and a test for each in CompareTest.

4.Given an array of ints, return the number of times that two 6's are next to each other in the array. Also count instances where the second "6" is actually a 7.

array667([6, 6, 2]) → 1 array667([6, 6, 2, 6]) → 1 array667([6, 7, 2, 6]) → 1

5.Given an array of ints, we'll say that a triple is a value appearing 3 times in a row in the array. Return true if the array does not contain any triples.

noTriples([1, 1, 2, 2, 1]) → true noTriples([1, 1, 2, 2, 2, 1]) → false noTriples([1, 1, 1, 2, 2, 2, 1]) → false

6.Given a string, return a new string where "not " has been added to the front. However, if the string already begins with "not", return the string unchanged. Note: use .equals() to compare 2 strings.

notString("candy") → "not candy" notString("x") → "not x" notString("not bad") → "not bad"

Slot 3 write these methods in Compare class( Compare.java) and a test for each in CompareTest.

7.Given an array of ints, return true if one of the first 4 elements in the array is a 9. The array length may be less than 4.

arrayFront9([1, 2, 9, 3, 4]) → true arrayFront9([1, 2, 3, 4, 9]) → false arrayFront9([1, 2, 3, 4, 5]) → false

8.Given a string, return a new string where the last 3 chars are now in upper case. If the string has less than 3 chars, uppercase whatever is there. Note that str.toUpperCase() returns the uppercase version of a string.

endUp("Hello") → "HeLLO" endUp("hi there") → "hi thERE" endUp("hi") → "HI"

9.Given a non-empty string and an int n, return a new string where the char at index n has been removed. The value of n will be a valid index of a char in the original string (i.e. n will be in the range 0..str.length()-1 inclusive).

missingChar("kitten", 1) → "ktten" missingChar("kitten", 0) → "itten" missingChar("kitten", 4) → "kittn"

aishwaryaneelakandan commented 3 years ago

Slot 1 https://github.com/aishwaryaneelakandan/Assignment/tree/master/Assignment/src

aishwaryaneelakandan commented 3 years ago

Slot 2 https://github.com/aishwaryaneelakandan/Assignment/tree/master/Assignment/src

aishwaryaneelakandan commented 3 years ago

Slot 3 https://github.com/aishwaryaneelakandan/Assignment/tree/master/Assignment/src