In String 1 section of Java Bat there are basic string problems in which you cannot use loops to solve the problem. We should use string functions like str.length(), str.substring(i,j) etc.
Make Tags Problem: The web is built with HTML strings like "Yay" which draws Yay as italic text. In this example, the "i" tag makes and which surround the word "Yay". Given tag and word strings, create the HTML string with tags around the word, e.g. "Yay".
Examples:
makeTags("i", "Yay") → "<i>Yay</i>"
makeTags("i", "Hello") → "<i>Hello</i>"
makeTags("cite", "Yay") → "<cite>Yay</cite>"
In this problem two words are passed as parameter to a method makeTags, one is 'tag' and other is 'word'. The makeTags method should return a string formatted in a way that the tag is around the word as like a HTML tag.
To solve this problem first we have to create a HTML tags from the given 'tag' string. For this we will create a start tag and an end tag.
Now we have to place these tags around the words.
So the Answer for this Java Bat Problem:
Make Tags Problem: The web is built with HTML strings like "Yay" which draws Yay as italic text. In this example, the "i" tag makes and which surround the word "Yay". Given tag and word strings, create the HTML string with tags around the word, e.g. "Yay".
Examples:
makeTags("i", "Yay") → "<i>Yay</i>"
makeTags("i", "Hello") → "<i>Hello</i>"
makeTags("cite", "Yay") → "<cite>Yay</cite>"
In this problem two words are passed as parameter to a method makeTags, one is 'tag' and other is 'word'. The makeTags method should return a string formatted in a way that the tag is around the word as like a HTML tag.
To solve this problem first we have to create a HTML tags from the given 'tag' string. For this we will create a start tag and an end tag.
String starttag = "<"+tag+">"; String endtag = "</"+tag+">"; |
Now we have to place these tags around the words.
String str = starttag+word+endtag; |
So the Answer for this Java Bat Problem:
public String makeTags(String tag, String word) { String starttag="<"+tag+">"; String endtag="</"+tag+">"; String str= starttag+word+endtag; return str; } |
No comments:
Post a Comment