Skip to content

DevVinciCod3/JC-Exploring-Java-String-Methods

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Exercise 1: length() - Finding the String's Size

img.png

Prediction:

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.

Observation:

the output is 14, same with my prediction

Exercise 2: charAt() - Accessing a Character

img_1.png

Prediction:

it will output white space, so we can say that we will see nothing.

Observation:

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 '

Exercise 3: substring() - Extracting a Part of a String

img_2.png

Prediction:

my expected output is: "is" base on my understanding it will exclude the last index in range.

Observation:

the output = "is", same with my prediction

Exercise 4: toUpperCase() and toLowerCase() - Changing Case

img_3.png

Prediction:

output 1: "THIS IS A TEST"

output 2: "this is a test"

Observation:

the output is the same with my prediction

Exercise 5: indexOf() - Finding a Character or Substring

img_4.png

Prediction:

base on the learning material the expected output is this:

Index of 'fox': 16

Index of 'z': 37

Index of 'cat': -1

Observation:

the output is what i expected.

Exercise 6: equals() vs. equalsIgnoreCase() - Comparing Strings

img_5.png

Prediction:

the expected output in each output is:

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")

Observation:

the output is same as predicted.

Exercise 7: replace() - Replacing Characters

img_6.png

Prediction:

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.

Observation:

same as predicted

Exercise 8: trim() - Removing Whitespace

img_7.png

Prediction:

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.

Observation:

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.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published