工作小驿

Ninja!

BlogJava 首页 新随笔 联系 聚合 管理
  103 Posts :: 0 Stories :: 32 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 王君 阅读(106) 评论(0)  编辑  收藏 所属分类: J2SE



标题  
姓名  
主页
验证码 *  
内容(请不要发表任何与政治相关的内容)  
  登录  使用高级评论  新用户注册  返回页首  恢复上次提交      
 
 
相关链接:
网站导航: