 
										
					
	
 2007-01-10 01:43
	    2007-01-10 01:43
   2007-01-10 10:14
	    2007-01-10 10:14
  我当时是先将String 转化为byte数组,然后取它截取位置的值拿出来比较,如果是在a,z之间或A,Z之间,就保留;否则就取一位做同样比较,如果不是在a,z之间或A,Z之间,同样保留;如果是的话就判断是汉字,所以不取这一位.最后再将byte数组转化为String 
想法跟楼上差不多,不过也不知道对不对.去试验下.
 2007-01-10 12:45
	    2007-01-10 12:45
   2007-01-10 13:21
	    2007-01-10 13:21
   我当时笔试时也就只是想到这个了,哪位大狭给点更好的点子啊
我当时笔试时也就只是想到这个了,哪位大狭给点更好的点子啊
写了程序之后才发现我那办法行不通,原因在于如果你判断到了那个是汉字,但无法判定是否删除或保留.
[此贴子已经被作者于2007-1-10 16:18:27编辑过]
 2007-01-10 16:07
	    2007-01-10 16:07
  用一个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]
 2007-01-10 16:30
	    2007-01-10 16:30