匹配的时候用了正则表达式
import java.util.Scanner;
import java.util.regex.Pattern;
class Client_port {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
String str = scan.next();
String rex ="((\\d{1,2}|25[0-5]|2[0-4]\\d|1\\d{2})\\.){3}(\\d{1,2}|25[0-5]|2[0-4]\\d|1\\d{2})";// 这里\\d的第一个\是对第二个\的转义,避免某些语言不识别,不加也是课可以的
Pattern pat = Pattern.compile(rex);// 编译正则表达式
boolean b = pat.matcher(str).matches();
if (b) {
System.out.println("匹配");
} else {
System.out.println("不匹配");
}
}
}