中文字幕天天躁日日躁狠狠躁,最近中文字幕大全免费版在线,最近2019免费中文字幕视频三,亚洲精品无码你懂的,亚洲国产精品成人精品小说

  • 相關(guān)軟件
    >java 面試中的一道編寫一個截取字符串的函數(shù) 創(chuàng)建者:webmaster 更新時間:2005-05-30 22:57

    編程:編寫一個截取字符串的函數(shù),輸入為一個字符串和字節(jié)數(shù),輸出為按字節(jié)截取的字符串。 但是要保證漢字不被截半個,如“我ABC”4,應(yīng)該截為“我AB”,輸入“我ABC漢DEF”,6,應(yīng)該輸出為“我ABC”而不是“我ABC+漢的半個”。




    package string;
    class SplitString
    {
    private String str;
    private int byteNum;

    public SplitString(){}

    public SplitString(String str,int byteNum)
    {
    this.str=str;
    this.byteNum=byteNum;

    }

    public void splitIt()
    {

    byte bt[]=str.getBytes();
    System.out.println("Length of this String ===>"+bt.length);
    if(byteNum>1)
    {
      if(bt[byteNum]<0)
      {
      String substrx=new String(bt,0,--byteNum);
      System.out.println(substrx);
      }else
      {
      String substrex=new String(bt,0,byteNum);
      System.out.println(substrex);
      }
     
    }else
    {
      if(byteNum==1)
      {
      if(bt[byteNum]<0)
      {
      String substr1=new String(bt,0,++byteNum);
      System.out.println(substr1);
      }else
      {
      String subStr2=new String(bt,0,byteNum);
      System.out.println(subStr2);
      }
      }else
      {
      System.out.println("輸入錯誤!??!請輸入大于零的整數(shù):");
      }
    }
    }
    }

    public class TestSplitString
    {
    public static void main(String args[])
    {
    String str="我ABC漢DEF";
    int num=6;
    SplitString sptstr = new SplitString(str,num);
    sptstr.splitIt();
    }
    }
    相關(guān)文章
    本頁查看次數(shù):