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


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


    網(wǎng)站導(dǎo)航:
     
    <2025年7月>
    293012345
    6789101112
    13141516171819
    20212223242526
    272829303112
    3456789

    導(dǎo)航

    統(tǒng)計(jì)

    常用鏈接

    留言簿(11)

    隨筆分類(48)

    文章分類(29)

    常去逛逛

    搜索

    積分與排名

    最新評(píng)論

    閱讀排行榜

    評(píng)論排行榜

    主站蜘蛛池模板: 啊灬啊灬别停啊灬用力啊免费看| 91午夜精品亚洲一区二区三区| 一个人看www在线高清免费看| www.xxxx.com日本免费| 亚洲日韩av无码中文| 亚洲三级电影网址| 国产午夜亚洲精品午夜鲁丝片| 韩国欧洲一级毛片免费 | 亚洲午夜国产片在线观看| 无人影院手机版在线观看免费 | 日韩亚洲变态另类中文| 国产精品高清全国免费观看| 91精品免费国产高清在线| 国产精品白浆在线观看免费| 精品国产呦系列在线观看免费| 看一级毛片免费观看视频| 美女视频黄免费亚洲| 亚洲高清无在码在线电影不卡| 亚洲国产日韩一区高清在线| 亚洲日韩精品无码专区网址| 亚洲熟女乱综合一区二区| 亚洲成av人在片观看| 国产精品99久久免费| 日日操夜夜操免费视频| 日本牲交大片免费观看| 69成人免费视频无码专区| www.黄色免费网站| 手机在线看永久av片免费| 久久国内免费视频| 久久久www成人免费毛片| 成年免费大片黄在线观看岛国| 一二三四免费观看在线视频中文版 | 亚洲天堂一区在线| 久久久亚洲AV波多野结衣| 亚洲视频网站在线观看| 亚洲系列国产精品制服丝袜第| 亚洲精品中文字幕麻豆| 亚洲国产高清视频在线观看| 亚洲三级中文字幕| 亚洲综合国产成人丁香五月激情| 亚洲一卡2卡3卡4卡5卡6卡 |