工作小驛

          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 王君 閱讀(293) 評論(0)  編輯  收藏 所屬分類: J2SE
          主站蜘蛛池模板: 中超| 皋兰县| 中卫市| 诸暨市| 浮山县| 潮州市| 吉木萨尔县| 瓮安县| 建阳市| 大连市| 延安市| 水城县| 定边县| 敦化市| 英山县| 宜宾县| 独山县| 洪雅县| 新宾| 茶陵县| 平舆县| 平原县| 辽中县| 航空| 黄冈市| 原平市| 陇南市| 陆良县| 大英县| 文水县| 富顺县| 大埔区| 无棣县| 库尔勒市| 万盛区| 丹寨县| 泾川县| 固安县| 太原市| 乌拉特后旗| 合川市|