工作小驛

          Ninja!

          BlogJava 首頁 新隨筆 聯系 聚合 管理
            103 Posts :: 0 Stories :: 36 Comments :: 0 Trackbacks
          import java.io.*;
          import java.util.regex.*;

          public class Printer {
          public static void main(String[] args) {
          System.out.println("
          Please enter the input string:
          ");
          BufferedReader reader =
          new BufferedReader(new InputStreamReader(System.in));
          String inputString;
          boolean isOK = false;
          try {
          while(!isOK) {
          if((inputString = reader.readLine()) != null) {
          if(inputString.length() > 200) {
          System.out.println("The string
          exceeds 200 characters.
          Please enter again!
          ");
          }
          else {
          Pattern regex = Pattern.compile("[^@#$%&*/^]+");
          Matcher matcher = regex.matcher(inputString);
          boolean isMatched = matcher.matches();
          if(!isMatched) {
          System.out.println("The String cant
          contain @,#,$,%,*,& and ^.
          Please enter again!
          ");
          }
          else {
          isOK = true;
          System.out.println("
          Your input
          string is:
          " + inputString);
          }
          }
          }
          }
          }
          catch(IOException e) {
          e.printStackTrace();
          }
          }
          }
          posted on 2007-09-17 07:59 王君 閱讀(289) 評論(0)  編輯  收藏 所屬分類: J2SE
          主站蜘蛛池模板: 文昌市| 鄂尔多斯市| 齐河县| 固始县| 洪洞县| 东乌珠穆沁旗| 台江县| 屏东县| 绵阳市| 芦山县| 凤台县| 五河县| 博乐市| 景泰县| 绵阳市| 洪泽县| 塘沽区| 宁远县| 星座| 珠海市| 都安| 海淀区| 九江市| 隆昌县| 连南| 板桥市| 宿迁市| 石台县| 张家界市| 黄平县| 新龙县| 久治县| 夏河县| 台南县| 收藏| 上林县| 郴州市| 南康市| 调兵山市| 昔阳县| 旺苍县|