java practice set 3
/*
Today we will solve some of the best problems in Java related to strings!. Here is the Chapter 3 – Practice Set
1. Write a Java program to convert a string to lowercase.
2. Write a Java program to replace spaces with underscores.
3. Write a Java program to fill in a letter template which looks like below:
letter = “Dear <|name|>, Thanks a lot”
Replace <|name|> with a string (some name)
4. Write a Java program to detect double and triple spaces in a string.
5. Write a program to format the following letter using escape sequence characters.
Letter = “Dear Harry, This Java Course is nice. Thanks”
*/
package com.company;
public class cwh_chapter3_practiceset {
public static void main(String[] args) {
//problem1
String name="Madhurima Moulik";
name =name.toLowerCase();
System.out.println(name);
//problem2
String text="to lower case";
text =text.replace("" , "_");
System.out.println(text);
//problem3
String letter= "Dear <|name|> , Thanks a lot!";
letter= letter.replace("<|name|>","MOON");
System.out.println(letter);
//problem4
String myString =" this strings contains duble and triple spaces";
System.out.println(myString.indexOf(" "));
System.out.println(myString.indexOf(" "));
//problem5
String myletter ="\t dear moon.\n\t this java couse is nice ,\n\t thankx!";
System.out.println(myletter);
}
}
Comments
Post a Comment