一道Java编程题,谢谢啦1
发布网友
发布时间:2024-03-09 16:48
我来回答
共1个回答
热心网友
时间:2024-04-09 17:33
public class MyStringBuilder1
{
static char alphabetic_delta = (char)('A' - 'a');
private StringBuilder sBuilder;
public MyStringBuilder1( String s ){
sBuilder = new StringBuilder( s );
}
public MyStringBuilder1 append( MyStringBuilder1 s )
{
if( s==null ) return this;
sBuilder.append( s.toString() );
return this;
}
public MyStringBuilder1 append( int i )
{
sBuilder.append( i );
return this;
}
public int length()
{
return sBuilder.length();
}
public char charAt(int index)
{
if( index < 0 || index >= sBuilder.length() )
return (char)-1;
return sBuilder.charAt( index );
}
public MyStringBuilder1 toLowerCase()
{
int length = sBuilder.length();
char charcode = 0;
for( int i=0;i<length;i++ ){
charcode = sBuilder.charAt( i );
if( charcode>='A' && charcode<='Z' ){
sBuilder.setCharAt( i, (char)(charcode - alphabetic_delta) );
}
}
return this;
}
public MyStringBuilder1 substring(int begin, int end)
{
if( begin >= sBuilder.length() )
return null;
if( end <= begin )
return null;
String str = sBuilder.substring(begin, end);
MyStringBuilder1 newstring = new MyStringBuilder1(str);
return newstring;
}
}