0% found this document useful (0 votes)
13 views1 page

Stringbuffer 9

The document defines a Stringbuffer class with a main method that compares the lengths of two strings, appends matching characters to a StringBuffer, and appends the remainder of the longer string.

Uploaded by

Dhanapriya S
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views1 page

Stringbuffer 9

The document defines a Stringbuffer class with a main method that compares the lengths of two strings, appends matching characters to a StringBuffer, and appends the remainder of the longer string.

Uploaded by

Dhanapriya S
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as ODT, PDF, TXT or read online on Scribd

public class Stringbuffer {

public class Assignment10 {

public static void main(String[] args) {


String a = "Helloo";
String b = "World123abc";

String bigger = a.length() > b.length() ? a : b;


String smaller = a.length() < b.length() ? a : b;

StringBuffer sb = new StringBuffer();

for (int i = 0; i < smaller.length(); i++) {


sb.append(a.charAt(i)).append(b.charAt(i));
}

sb.append(bigger.substring(smaller.length(),
bigger.length()));

System.out.println(sb);
}

You might also like