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


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


    網站導航:
     
    <2025年7月>
    293012345
    6789101112
    13141516171819
    20212223242526
    272829303112
    3456789

    導航

    統計

    常用鏈接

    留言簿(11)

    隨筆分類(48)

    文章分類(29)

    常去逛逛

    搜索

    積分與排名

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 美女被吸屁股免费网站| 日本亚洲欧美色视频在线播放 | 99久久99这里只有免费费精品| 亚洲精品亚洲人成人网| 思思久久99热免费精品6 | 亚洲中文字幕无码一久久区| 免费一级毛suv好看的国产网站| 国产最新凸凹视频免费| 色九月亚洲综合网| 亚洲国产精品碰碰| 成人毛片100免费观看| 亚洲伊人久久精品影院| a毛片久久免费观看| 亚洲AV无码国产丝袜在线观看| 亚洲视频在线免费观看| 亚洲精品无码久久毛片波多野吉衣| 亚洲日韩国产精品乱-久| 中文字幕人成无码免费视频| 日本成人免费在线| 精品成人一区二区三区免费视频| 亚洲成av人片不卡无码久久| 中文字幕在线观看免费| 精品亚洲A∨无码一区二区三区| 国产免费丝袜调教视频| 亚洲欧美成aⅴ人在线观看| 午夜亚洲av永久无码精品| 9久热精品免费观看视频| 亚洲成人免费在线| 特级做A爰片毛片免费69| 另类专区另类专区亚洲| 亚洲午夜久久久久久久久电影网| 久久国产乱子伦免费精品| 一本色道久久88亚洲精品综合 | 久久乐国产综合亚洲精品| 免费国产a国产片高清网站| 国产一级一毛免费黄片| 亚洲国产高清在线精品一区| 免费人成视频在线观看不卡| 久久黄色免费网站| 亚洲国产精品18久久久久久| 亚洲人成在线播放网站|