<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)

    常去逛逛

    搜索

    積分與排名

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 亚洲高清在线观看| 亚洲av日韩片在线观看| 一区二区亚洲精品精华液| 污污网站免费观看| 亚洲高清在线观看| 99爱在线精品视频免费观看9| 67194成是人免费无码| 亚洲自国产拍揄拍| 国产福利免费视频| 免费观看AV片在线播放| 国产午夜亚洲不卡| 日本高清免费观看| 亚洲国产电影av在线网址| 日韩精品无码免费视频| 国产高清不卡免费在线| 中文字幕专区在线亚洲| 热99RE久久精品这里都是精品免费 | 美女羞羞免费视频网站| 国产精品亚洲mnbav网站| 免费国产在线视频| 亚洲一级毛片免费看| 久久免费视频网站| 亚洲国产精品久久久久秋霞影院| 日本精品人妻无码免费大全| 苍井空亚洲精品AA片在线播放| 亚洲一区二区三区在线视频 | 亚洲免费一级视频| 亚洲AV日韩AV一区二区三曲| 国产福利电影一区二区三区,亚洲国模精品一区 | 国产小视频免费观看| 成av免费大片黄在线观看| 亚洲人成无码网站久久99热国产| 香蕉免费一级视频在线观看| 亚洲日韩区在线电影| 日本大片在线看黄a∨免费| 亚洲一区二区三区久久| 免费人成无码大片在线观看| 暖暖日本免费中文字幕| 亚洲av无码av在线播放| 久久精品九九亚洲精品天堂| 国产免费AV片在线观看播放|