工作小驛

          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 王君 閱讀(288) 評論(0)  編輯  收藏 所屬分類: J2SE
          主站蜘蛛池模板: 株洲市| 班戈县| 皋兰县| 汝城县| 那曲县| 浮山县| 车险| 读书| 囊谦县| 北宁市| 海南省| 宣恩县| 颍上县| 富蕴县| 桓台县| 巴林左旗| 建宁县| 同仁县| 惠安县| 海晏县| 奈曼旗| 揭东县| 吐鲁番市| 鹤峰县| 温宿县| 阿巴嘎旗| 无棣县| 天柱县| 内江市| 潮安县| 龙州县| 三明市| 凤台县| 灵璧县| 建平县| 鹤岗市| 中西区| 伽师县| 十堰市| 文登市| 襄垣县|