作业7.doc

  1. 1、本文档共4页,可阅读全部内容。
  2. 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
作业7

作业一: 创建一个Student类,该有String类型的学号stuNo,String类型的姓名,要求将该类所有的成员变量进行封装,并且提供公共的getter和setter方法,重写equals方法,只要学生的学号相同即返回true,重写toString 方法,toString方法返回值类似”姓名:张三 学号:201301 ” public class Student private String stuNo; private String name; public Student String stuNo,String name this.name name; this.stuNo stuNo; public String getStuNo return stuNo; public void setStuNo String stuNo this.stuNo stuNo; public String getName return name; public void setName String name this.name name; public boolean equals Object obj Student st Student obj; boolean b this.stuNo.equals st.stuNo ;//学号是否相同 return b; public String toString return "姓名:"+this.name+",学号:"+this.stuNo; Test: public class Test public static void main String[] args Student a new Student "12345","张三" ; Student b new Student "12345","王二" ; System.out.println a.equals b ; System.out.println a.toString ; 作业二: 编写敏感词过滤程序 在网络程序中,如聊天室、聊天软件等,经常需要对一些用户所提交的聊天内容中的敏感性词语进行过滤。如“性”、“色情”、“爆炸”、“恐怖”、“枪”等,这些都不可以在网上进行传播,需要过滤掉或者用其他词语替换掉。 思路:将用户的聊天内容保存到一个字符串对象或一个StringBuilder对象中,然后与敏感词语进行比对。如果属于敏感词语,就过滤掉或替换掉。 public class Mgci static String[] srr "性", "色情", "爆炸", "恐怖", "枪" ; public static String filter String str for int i 0; i srr.length; i++ //srr[i].length ; str str.replaceAll srr[i],"*" ; return str; public static void main String[] args String s "我正在看恐怖电影"; System.out.println Mgci.filter s ; 用户名长度大于等于6位,必须包含数字和英文字母 密码长度大于等于8位,必须包含特殊符号_或者$,英文字母以及数字 以上两个条件同时成立注册才能成功。 public class UserUtil public static boolean username String name if name.length 6 return false; boolean haveZ false;//记录是否有字母 boolean haveN false;//记录是否有数字 char [] crr name.toCharArray ;//将字符串拆分为字符数组 for int i 0; i crr.length; i++ char c crr[i]; if c 'a' && c 'z' haveZ true;//发现小写字母 if c 'A' && c 'Z' haveZ true;//发现大写字母 if c '0' && c '9' haveN true;//发现数字 if haveZ && haveN //字母和数字同时存在 return true; return false; public static boolean password String pass if pass.length 8 //长度小于8 System.out.prin

文档评论(0)

abf4675328 + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档