My expected output is "The length of the string is: 14" because it will also count the white space and symbols because those have their own index.
the output is 14, same with my prediction
it will output white space, so we can say that we will see nothing.
I made a rookie mistake i forgot that the when we use charAt it use index, so it will start from 0. that's why index 5 = character ' l '
my expected output is: "is" base on my understanding it will exclude the last index in range.
the output = "is", same with my prediction
output 1: "THIS IS A TEST"
output 2: "this is a test"
the output is the same with my prediction
Index of 'fox': 16
Index of 'z': 37
Index of 'cat': -1
the output is what i expected.
Output 1 = false. (because the 'J' in str1 is capitalize but the 'j' in str2 is small)
Output 2 = true. (because str1 and str3 has identical case on character 'J')
Output 3 = true. (because we use .equalsIgnoreCase so it ignore the case and just focus on the word "Java")
the output is same as predicted.
Based on the code provided, my expected output will be:
Original: I like cats. Cats are cute.
Replaced: I like dogs. Cats are cute.
The output will be this because the replace() method in Java is case-sensitive. It only replaces the lowercase "cats" with "dogs" but leaves the capitalized "Cats" unchanged.
same as predicted
Based on the code provided, the output will be:
Padded string length: 20
Trimmed string: 'Lots of spaces'
Trimmed string length: 14
The output will be this because the trim() method removes leading and trailing whitespace from the string. The original string has 2 spaces at the beginning and 2 at the end, along with 14 characters in "Lots of spaces". The original string's length is therefore 18. After trimming, the leading and trailing spaces are gone, leaving only the 14 characters, which is the new length.
the same as predicted but there are some mistake of me counting the spaces i count it as 2 in front and 2 in the end. so for me its 18 in total but the exact length is 20 because its 3 space in front and back.