-
控制台输入密码, 使用正则判断密码是否是8位的数字
-
控制台输入电话号码, 使用正则表达式判断输入的号码是否正确
-
控制台输入邮箱,使用正则表达式判断输入的邮箱是否正确
-
将字符串
"a1b22c333d4444e"
中连续的3个数字用大写A替换 -
打印字符串
"buka is good"
反转效果 -
将字符串
"buka is good"
中的每一个单词反转并打印package com.test; import com.sun.scenario.effect.impl.sw.sse.SSEBlend_SRC_OUTPeer; import java.util.Scanner; import java.util.regex.Matcher; public class Test { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String mm = "\\d{8}"; System.out.println("请输入密码: "); String a = sc.next(); System.out.println(a.matches(mm)); System.out.println("--------------------------------"); String dhhm = "^(13[0-9]|14[5|7]|15[0|1|2|3|5|6|7|8|9]|18[0|1|2|3|5|6|7|8|9])\\d{8}$"; System.out.println("请输入电话号码: "); String b = sc.next(); System.out.println(b.matches(dhhm)); System.out.println("--------------------------------"); String yx = "^([A-Za-z0-9_\\-\\.])+\\@(163.com|qq.com|42du.cn)$"; System.out.println("请输入邮箱: "); String c = sc.next(); System.out.println(c.matches(yx)); System.out.println("--------------------------------"); String lx="(\\d{3})"; String d="a1b22c333d4444e"; String e=d.replaceAll(lx,"AAA"); System.out.println(e); System.out.println("--------------------------------"); StringBuilder f =new StringBuilder(); f.append("buka is good"); f.reverse(); System.out.println(f); System.out.println("--------------------------------"); String g="buka is good"; String[] hs = g.split(" "); for (String h : hs ){ StringBuilder i = new StringBuilder(h).reverse(); System.out.println(i); } System.out.println("--------------------------------"); } }
使用正则表达式完成测试练习
最新推荐文章于 2024-08-20 21:55:11 发布