import java.util.regex.*;
import java.util.Scanner;class wrenwren
{
public static void main(String args[]) throws Exception
{
Scanner cs = new Scanner(System.in);
System.out.println("输入:");
String a = cs.ReadLine();
Pattern p = Pattern.compile("w.5{2}");
Matcher m = p.matcher(p);
if(m.find()){
System.out.println(a);
}
}
}
import java.util.Scanner;class wrenwren
{
public static void main(String args[]) throws Exception
{
Scanner cs = new Scanner(System.in);
System.out.println("输入:");
String a = cs.ReadLine();
Pattern p = Pattern.compile("w.5{2}");
Matcher m = p.matcher(p);
if(m.find()){
System.out.println(a);
}
}
}
首先Scanner对象就没有readLine方法,即使有方法,按照java的编写规范,是绝对不会出现类似ReadLine此类以大写字母开头的方法的,还有,猜楼主的意思是要分割输入的字符串,Scanner类就有带利用正则表达式分割字符串的方法。哦,顺便再说一句,楼主写的类名首字母也要大写啊。多个单词每个单词首字母大写
import java.util.regex.Matcher;
import java.util.regex.Pattern;public class wrenwren {
public static void main(String args[]) throws Exception
{
Scanner cs = new Scanner(System.in);
System.out.println("输入:");
String a="";
while(cs.hasNextLine()){
a=cs.nextLine();
Pattern p = Pattern.compile("w.5{2}");
Matcher m = p.matcher("w.5{2}");
if(m.find()){
System.out.println(a);
}
}
}
}
import java.util.Scanner;class wrenwren
{
public static void main(String args[]) throws Exception
{
Scanner cs = new Scanner(System.in);
System.out.println("输入:");
String a = cs.next();
Pattern p = Pattern.compile("w.5{2}");
Matcher m = p.matcher(a);
if(m.find()){
System.out.println(a);
}
}
}