Learn-dsa..in 30 days!



























CC-17 : Find length of String.

Description:

Given an input String, find its length.

Test cases and expected outputs:

Input Parameters Expected outputs
Original String: receive Length: 7
Original String:”” Length: 0

Pseudocode:

stringLength(str):

If str.length==0:
return str.
Else :
Set variable reducedString to str with first character removed.
Return number calculated by adding 1 to return value from reverseString(reducedString).

Code:

public int stringLength(String str) {
	if (str.length() == 0) {
		return 0;
	}else {
		String reducedStr=str.substring(1);
		return stringLength(reducedStr)+1;
	}
		
}

Click here to download and run code and test cases !