用一个for循环搞定
[CODE]
import java.io.*;
public class SelectString
{
private String teststring;
public SelectString( String test )
{
this.teststring = test;
}
public String select( int i ) throws IOException
{
byte[] temp = teststring.getBytes();
int kick = 0;
ByteArrayOutputStream bos = new ByteArrayOutputStream();
for( int m = 0; m < i; m ++ )
{
if ( isChinese( temp[ m ] ) )
kick ++;
}
if ( kick % 2 == 0 )
bos.write( temp, 0, i );
else
bos.write( temp, 0, i -1 );
byte[] result = bos.toByteArray();
return new String( result );
}
private boolean isChinese( byte test )
{
//char num = (char)test;
if( ( test > 'a'-1 && test < 'z'-1 ) || ( test > 'A'-1 && test < 'Z'-1 ) )
return false;
else
return true;
}
public static void main( String[] args ) throws IOException
{
SelectString selectstring = new SelectString( "A章晨BC" );
System.out.println( selectstring.select( 3 ) );
}
}
[/CODE]