<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狂 閱讀(428) 評論(0)  編輯  收藏 所屬分類: JavaSE


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


    網站導航:
     
    <2025年5月>
    27282930123
    45678910
    11121314151617
    18192021222324
    25262728293031
    1234567

    導航

    統計

    常用鏈接

    留言簿(11)

    隨筆分類(48)

    文章分類(29)

    常去逛逛

    搜索

    積分與排名

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 亚洲色欲久久久久综合网| 久久九九亚洲精品| 精品久久久久久国产免费了| 久久亚洲免费视频| 天天操夜夜操免费视频| 亚洲精品视频免费观看| 亚洲国产综合精品| 亚洲精品视频在线观看你懂的 | 久久九九全国免费| 亚洲中文字幕AV在天堂| 久久精品国产亚洲精品| 最近2019中文字幕mv免费看| 亚欧乱色国产精品免费视频| 亚洲一区二区三区免费视频| 日韩一卡2卡3卡4卡新区亚洲| 国产va精品免费观看| 精品久久久久久国产免费了| 亚洲综合色区中文字幕| 中文字幕亚洲一区| 午夜视频免费成人| 香蕉免费一区二区三区| 免费一级做a爰片久久毛片潮| 亚洲综合色丁香麻豆| 亚洲成a人片在线播放| av大片在线无码免费| a级毛片在线视频免费观看| 亚洲综合欧美色五月俺也去| 亚洲AV无码欧洲AV无码网站| 亚洲国产精品无码久久九九| 无码日韩人妻av一区免费| 久久久久免费精品国产| 一区视频免费观看| 久久水蜜桃亚洲AV无码精品 | 在线观看亚洲电影| 亚洲一区在线观看视频| 亚洲av午夜成人片精品网站| 亚洲国产成人久久一区久久| 国产精品美女自在线观看免费| 999在线视频精品免费播放观看| 黄页免费在线观看| 国产特黄特色的大片观看免费视频|