Java Lab Tutorial 07
Java Lab Tutorial 07
Objectives:
After the completion of this lab, students should be able to:
Declare and create Strings.
Apply some operations on Java Strings
Lab Exercises:
Problem Description:
Write a Java program (StringOperations1.java) that performs some operations on
the following string literal: "Welcome! This is "CS110" Course".
Create an object of class String called str that hold the above string literal,
Print out the string str,
Convert all alphabets to upper-case letters and print out the result,
Convert all alphabets to lower-case letters and print out the result,
Print out the length of the string,
Print out the index of the word Course,
Remove the 1st three occurrences of the char 'c' or 'C' and print out the result,
Search for CS110 and replace it with CE211.
Sample output:
Problem Description:
Write a Java program (StringOperations2.java) that performs some operations on
the following strings (String s1 = "Ali", String s2 = "Magdi", String s3 = "[[]]").
Compare s1 and s2 to find out which one comes first in alphabetical order,
Create a new string that is string s2 in the middle of the string s3,
Create a new string that is the first char of s1 and the last char of s2,
Print out the string of length 3 from the middle of string s2.
Sample output: