// Program displays some facts about a string public class DebugSeven3 { public
ID: 3766677 • Letter: #
Question
// Program displays some facts about a string
public class DebugSeven3
{
public static void main(String[] args)
{
String quote =
"Honesty is the first chapter in the book of wisdom. - Thomas Jefferson";
System.out.println("index.of('f') is: " + indexOf('f'));
System.out.println("index.of('x') is: " + indexOf('x'));
System.out.println("char.At(5) is: " + charAt(5));
System.out.println("endsWith("daughter") is: " + quote.endswith("daughter"));
System.out.println("endsWith("son") is: " + quote.endswith("son"));
System.out.println("replace('e', '*') is: " + quote.replace('e', 'M'));
}
}
Explanation / Answer
public class NewClass {
public static void main(String[] args)
{
String quote =
"Honesty is the first chapter in the book of wisdom. - Thomas Jefferson";
System.out.println("index.of('f') is: " +quote.indexOf('f'));
System.out.println("index.of('x') is: " +quote.indexOf('x'));
System.out.println("char.At(5) is: " +quote.charAt(5));
System.out.println("endsWith("daughter") is: " +quote.endsWith("daughter"));
System.out.println("endsWith("son") is: " +quote.endsWith("son"));
System.out.println("replace('e', 'M') is: " +quote.replace('e', 'M'));
}
}
outpus:-
index.of('f') is: 15
index.of('x') is: -1
char.At(5) is: t
endsWith("daughter") is: false
endsWith("son") is: true
replace('e', 'M') is: HonMsty is thM first chaptMr in thM book of wisdom. - Thomas JMffMrson
1.In a string class use index.of('f') then display the index number of "f" in the given string.Index start from zero.
2.In a string class use index.of('x') then display the index number of "f" in the given string.but don have the letter disply -1.
3.In a string class use char.At(5) then display the charcter of tyhe given string index number "5" .Index start from zero.
4..In a string class use endsWith("string value") in this method return the bollen value true or false.
5.In a string class use replace('e','M') in this method replace the charcter "M" by the place of "e".
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.