Skip to content

A-Katsuro-C/Lab-Working-with-String-Methods

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

3 Commits
ย 
ย 
ย 
ย 

Repository files navigation

Lab-Working-with-String-Methods

Task 1: Working with String Methods

Create a new Java class called StringLab.

Inside the main() method:

Create a String variable with the value: " Welcome to the Java String Lab! ". Use the following methods on this string and print the results: length(): Print the length of the string. charAt(): Print the character at index 7. substring(): Extract and print the word "Java" from the string. toUpperCase() and toLowerCase(): Print both the uppercase and lowercase versions. indexOf(): Find and print the index of the first occurrence of "Java". contains(): Check if the string contains the word "Lab" and print the result. replace(): Replace "Java" with "Java Programming" and print the result. split(): Split the string by spaces and print each word using a for loop. trim(): Trim any leading or trailing spaces and print the result. equals() and equalsIgnoreCase(): Compare the string "java string lab!" with " Welcome to the Java String Lab! " and print the results.

Task 2: Loop Challenges with Strings

๐ŸŒ€ For Loop: Count Vowels Write a for loop to count how many vowels (a, e, i, o, u) are in the original string. Print the result.

๐Ÿ” While Loop: Check for Palindrome Create a new String variable with a single word (e.g., "racecar").

Use a while loop to check if the word is a palindrome (reads the same forward and backward). Print whether it is or not.

๐Ÿ”‚ Do...While Loop: Input Validation Prompt the user to enter a sentence.

Use a do...while loop to repeat the prompt until the user types a sentence that contains the word "Java".

Once the condition is met, print "Thank you!".

Task 3: Working with StringBuilder

Create a StringBuilder object initialized with "StringBuilder Lab". Perform the following operations:

append(): Add " - Learning Java" to the StringBuilder. insert(): Insert " is fun" after the word "Lab". delete(): Delete the word "Learning" from the StringBuilder. reverse(): Reverse the entire string and print it.

Task 4: Working with StringBuffer

Create a StringBuffer object initialized with "Multithreading Lab".

Perform the same operations as in Task 3: append() insert() delete() reverse()

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages