新手必会java实例111个(会了此111个实例,便真实进入java之殿堂)

1.定义一个新类,并输出

class Student{
   public Student(){
       name="xiaoming";age=22;sex=ture;score=100.0;
       }

  void show(){
       System.out.println(name+age+sex+score);
  }

  public static void main(String args[]){
    String name;int age;boolean sex;double score;
    Student st=new Student();
    st.show();
  }
}

1.正则

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class test {
	public static void main(String[] args) {
		Pattern p = Pattern.compile("(?<=href=\").*(?=\">)");
		String str ="<li id=\"yaodian1\"><a class=\"yaodianlist\" target=\"_blank\" href=\"/Storelis/storelist!detail.html2?id=133488 \">阿凡达</a></li>";
		Matcher m = p.matcher(str);
		while(m.find())
			System.out.println(m.group());
	}
}




你可能感兴趣的:(java)