<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    某外包公司筆試題

    編程題:去掉字符串中多余的"0",
    例如
    0-->0
    3-->3
    000-->0
    01010-->101
    301100-->3011
    00103-->103
    1020.00-->1020
    001.0100-->1.01
    00.003-->0.003
    若字符串中字符(,E+-)則為非法字符串。

    public class RemoveZero {

        
    /**
             * 
    @param args
             
    */
        
    static String removeFirst(String str) {
        
    while (true) {
            
    if (str.length() > 1) {
            
    char c = str.charAt(0);
            
    char nextC = str.charAt(1);
            
    if (c != '0') {
                
    break;
            } 
    else {
                
    if (nextC == '.') {
                
    break;
                } 
    else {
                str 
    = str.substring(1);
                }
            }
            } 
    else {
            
    break;
            }
        }
        
    return str;
        }

        
    static String removeLast(String str) {
        
    while (true) {
            
    if (str.length() > 1) {
            
    char c = str.charAt(str.length() - 1);
            
    char beforeC = str.charAt(str.length() - 2);
            
    if (c != '0') {
                
    break;
            } 
    else {
                
    if (beforeC == '.') {
                str 
    = str.substring(0, str.length() - 2);
                
    break;
                } 
    else {
                str 
    = str.substring(0, str.length() - 1);
                }
            }
            } 
    else {
            
    break;
            }
        }
        
    return str;
        }

        
    static boolean isCorrect(String str) {
        
    return !str.contains("E"&& !str.contains(","&& !str.contains("+")
            
    && !str.contains("-");
        }

        
    public static void main(String[] args) {
        String str 
    = "003E+3";
        
    if (isCorrect(str)) {
            System.out.println(str 
    + "-->" + removeLast(removeFirst(str)));
        } 
    else {
            System.out.println(
    "字符串中含有非法字符(,E+-)!");
        }
        str 
    = "0";
        
    if (isCorrect(str)) {
            System.out.println(str 
    + "-->" + removeLast(removeFirst(str)));
        } 
    else {
            System.out.println(
    "字符串中含有非法字符,E+-!");
        }
        str 
    = "3";
        
    if (isCorrect(str)) {
            System.out.println(str 
    + "-->" + removeLast(removeFirst(str)));
        } 
    else {
            System.out.println(
    "字符串中含有非法字符,E+-!");
        }
        str 
    = "000";
        
    if (isCorrect(str)) {
            System.out.println(str 
    + "-->" + removeLast(removeFirst(str)));
        } 
    else {
            System.out.println(
    "字符串中含有非法字符,E+-!");
        }
        str 
    = "01010";
        
    if (isCorrect(str)) {
            System.out.println(str 
    + "-->" + removeLast(removeFirst(str)));
        } 
    else {
            System.out.println(
    "字符串中含有非法字符,E+-!");
        }
        str 
    = "301100";
        
    if (isCorrect(str)) {
            System.out.println(str 
    + "-->" + removeLast(removeFirst(str)));
        } 
    else {
            System.out.println(
    "字符串中含有非法字符,E+-!");
        }
        str 
    = "00103";
        
    if (isCorrect(str)) {
            System.out.println(str 
    + "-->" + removeLast(removeFirst(str)));
        } 
    else {
            System.out.println(
    "字符串中含有非法字符,E+-!");
        }
        str 
    = "1020.00";
        
    if (isCorrect(str)) {
            System.out.println(str 
    + "-->" + removeLast(removeFirst(str)));
        } 
    else {
            System.out.println(
    "字符串中含有非法字符,E+-!");
        }
        str 
    = "001.0100";
        
    if (isCorrect(str)) {
            System.out.println(str 
    + "-->" + removeLast(removeFirst(str)));
        } 
    else {
            System.out.println(
    "字符串中含有非法字符,E+-!");
        }
        str 
    = "00.003";
        
    if (isCorrect(str)) {
            System.out.println(str 
    + "-->" + removeLast(removeFirst(str)));
        } 
    else {
            System.out.println(
    "字符串中含有非法字符,E+-!");
        }
        }
    }


    posted on 2008-03-05 14:21 我為J狂 閱讀(427) 評論(0)  編輯  收藏 所屬分類: JavaSE


    只有注冊用戶登錄后才能發(fā)表評論。


    網(wǎng)站導航:
     
    <2025年5月>
    27282930123
    45678910
    11121314151617
    18192021222324
    25262728293031
    1234567

    導航

    統(tǒng)計

    常用鏈接

    留言簿(11)

    隨筆分類(48)

    文章分類(29)

    常去逛逛

    搜索

    積分與排名

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 免费无码一区二区三区蜜桃大| 久久久久成人片免费观看蜜芽| 久久精品无码一区二区三区免费 | 日韩免费码中文在线观看| 成人性生交大片免费看午夜a | 亚洲精品乱码久久久久久久久久久久| 一级免费黄色毛片| 中文字幕第一页亚洲| 久久免费99精品国产自在现线| 国产午夜亚洲精品理论片不卡| 4hu四虎免费影院www| 亚洲国产精品国自产拍AV| 日韩免费视频一区二区| 亚洲五月六月丁香激情| 青青青国产在线观看免费| 亚洲成人激情小说| 国产精品国产午夜免费福利看| 免费人成再在线观看网站| 亚洲日韩欧洲乱码AV夜夜摸| 免费黄色电影在线观看| 亚洲另类图片另类电影| 国内大片在线免费看| 免费一级毛suv好看的国产网站| 精品亚洲一区二区三区在线观看| 永久免费AV无码网站国产| 亚洲国产电影在线观看| 免费一级毛片女人图片| 日韩精品无码免费专区网站| 亚洲免费在线观看视频| 全部免费国产潢色一级| 国产成人久久AV免费| 最新国产精品亚洲| 亚洲人午夜射精精品日韩| 久久99精品免费视频| 亚洲日韩AV一区二区三区中文 | 国产自偷亚洲精品页65页| 午夜精品射精入后重之免费观看 | 久久免费动漫品精老司机 | 亚洲va无码手机在线电影| 免费影院未满十八勿进网站| 国产免费久久精品丫丫|