#1. Take the code from below and make it the main method in a class named String
ID: 3629541 • Letter: #
Question
#1. Take the code from below and make it the main method in a class named StringFun.
public static void main(String[] args) {
StringBuffer sb = new StringBuffer();
System.out.println ("The original value of sb is " + sb);
sb.append("I love Java and Java loves me!!");
System.out.println(sb);
sb.insert(20," really");
System.out.println(sb);
sb.replace(0,1,"My puppy dog");
System.out.println(sb);
}
Add lines of code so that the final output looks like the following:
1. The original value of sb is
2. I love Java and Java loves me!!
3. I love Java and Java really loves me!!
4. My puppy dog love Java and Java really loves me!!
5. My puppy dog loves Java and Java really loves me!!
6. My puppy loves Java and Java really loves me!!
7. !!em sevol yllaer avaJ dna avaJ sevol yppup yM
8. !!em sevol yllaer avaJ dna avaJ sevol yppup yM
9. The size of the final value of sb is 46
Explanation / Answer
please run the updated main method below: public static void main(String[] args) { StringBuffer sb = new StringBuffer(); System.out.println ("The original value of sb is " + sb); sb.append("I love Java and Java loves me!!"); System.out.println(sb); sb.insert(20," really"); System.out.println(sb); sb.replace(0,1,"My puppy dog"); System.out.println(sb); sb.insert(17, "s"); System.out.println(sb); sb.delete(8, 12); System.out.println(sb); sb.reverse(); System.out.println(sb); System.out.println(sb); System.out.println("The size of the final value of sb is "+sb.length()); } please rate.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.