admin管理员组文章数量:1579086
这只是一篇我自己学习java的流水账笔记,包含了以下内容,全是基础代码示例,希望对正在学习java的小伙伴有帮助
- java GUI贪吃蛇:[Daily] Snake
- java正则表达式:Regular Expression
- 双向链表:[Daily]Two-way loopback linked list
Regular Expression
Simple practice
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Test1 {
public static void main(String[] args) {
//初步认识Pattern & Matcher
/*
print("初步认识Pattern & Matcher");
print("abc".matches("..."));
print("a3456677a".replaceAll("\\d", "-"));
Pattern p = Patternpile("[a-z]{3}");
Matcher m = p.matcher("abc");
print(m.matches());
print("");
*/
//初步认识 . * + ?
/*
print("初步认识 . * + ?");
print("TEST .");//一个任意字符
print("aaa".matches("a.a"));
print("ata".matches("a.a"));
print("TEST *");//0个或多个
print("".matches("a*"));
print("a".matches("a*"));
print("TEST +");//一个或多个
print("".matches("a+"));//false
print("a".matches("a+"));
print("TEST ?");//0个或一个
print("".matches("a?"));
print("a".matches("a?"));
print("aa".matches("a?"));//false
print("TEST others");
print("234567899".matches("\\d{3,100}"));
print("192.168".matches("\\d{1,3}\\.\\d{1,3}"));
print("192".matches("[0-2][0-9][0-5]"));
print("");
*/
//认识范围
/*
print("TEST []");
print("a".matches("[abc]"));
print("a".matches("[^abc]"));//取反false
print("A".matches("[a-zA-Z]"));
print("A".matches("[a-z]|[A-Z]"));
print("A".matches("[a-z[A-Z]]"));
print("R".matches("[A-Z&&[RGB]]"));//交集
*/
//认识 \d \D \s \S \w \W \
/*
print("认识 \\d \\D \\s \\S \\w \\W \\");
print("4".matches("\\d"));// \d [0-9]
print("4".matches("\\D"));// \D [^0-9]
print(" ".matches("\\s"));// \s 空白字符 [\t\n\x0B\f\r]
print(" ".matches("\\S"));// \s 反空白字符 [^\s]
print("a".matches("\\w"));// \w [a-zA-Z_0-9]
print("a".matches("\\W"));// \w [^\w]
print("\\".matches("\\\\"));// 正则"\\\\" 表示 \
print("abc8881&".matches("[a-z]{1,3}\\d+[%^&]+"));
*/
//boundary 边界匹配
/*
print("边界匹配");//^表示开头 $表示结束
print("hello world".matches("^h.*d$"));
print("hello world".matches(".*ld$"));
print("hello world".matches("^h[a-z]{1,4}\\b.*"));
*/
//practice
/*
print("practice");
print("aaa 8888c".matches(".*\\b\\d{4}."));
print("745998763@qq".matches("\\w+@\\w+\\.[A-Za-z]{2,14}"));
print("a-".matches("\\w[-]"));
print(".".matches("[\\w[.-]]"));
print("+".matches("[+]+"));
print("+q".matches("[+].+"));
print("-".matches("[-A-Za-z0-9]"));
*/
//matches find looking at
/*
print("matches find looking at");
Pattern p = Patternpile("[a-z]{2,4}");
Matcher m = p.matcher("ab-abd-abcf-OO");
print(m.matches());
m.reset();
print(m.find());
print(m.start() + "-" + m.end());
print(m.find());
print(m.start() + "-" + m.end());
print(m.find());
print(m.start() + "-" + m.end());
print(m.find());
//print(m.start() + "-" + m.end());
print(m.lookingAt());
print(m.lookingAt());
print(m.lookingAt());
print(m.lookingAt());*/
//replacement
/*
print("replacement");
Pattern p = Patternpile("sakura",Pattern.CASE_INSENSITIVE);
String str = "sakura SAKURA saKURA SAkura ILoveSakura YouLoveSakuraToo";
Matcher m = p.matcher(str);
//print(m.replaceAll("SAKURA"));
int i = 1;
StringBuffer buf = new StringBuffer();
while(m.find()){
if(i%2 == 0){
m.appendReplacement(buf, "sakura");
}else {
m.appendReplacement(buf, "SAKURA");
}
i++;
}
m.appendTail(buf);
print(buf);*/
//group
/*
print("group");
Pattern p = Patternpile("([a-z]{1,3})([0-9]{1,2})");
Matcher m = p.matcher("qwe09 asd78 saj67");
while(m.find()){
print(m.group(1));
print(m.group(2));
}*/
//
//print("a".matches("[a-z&&[^bc]]"));//差集
//Greedy Reluctant Possessive
/*
String s = "aahsjkhjdskka";
//Matcher m = Patternpile("[a-z]+?").matcher(s);
//Matcher m = Patternpile("[a-z]*?").matcher(s);
//Matcher m = Patternpile("[a-z]??").matcher(s);
//Matcher m = Patternpile("[a-z]{2,5}").matcher(s);
Matcher m = Patternpile("[a-z]{2,5}?").matcher(s);
while(m.find()){
print(m.group());
print(m.start()+"-"+m.end());
}*/
//logic operators
//print("a".matches("[([a-z]|[0-9])[a-z][0-9]]+"));
//print("0g9ag8".matches("(([a-z]|[0-9])[a-z][0-9])+"));
/*
Matcher m = Patternpile(".{3}(?=a)").matcher("444a66b");
while(m.find()){
print(m.group());
}*/
//back reference
/*
Matcher m = Patternpile("([a-z][a-z])\\1").matcher("ababcdef");
while(m.find()){
print(m.group());//abab 和第一个组相同
}*/
/*Matcher m = Patternpile("([a-z]([a-z]))\\2").matcher("abbcddefr");
while(m.find()){
print(m.group());//abb cdd和第二个组相同,第二个组被第一个组包含
}*/
print("JaVa".matches("(?i)(java)"));
}
public static void print(Object o){
System.out.println(o);
}
}
[Daily]Two-way loopback linked list
public class NodeLinkedList{
public static void main(String[] args){
List list = new List(500);
print(list.length);
Count3Quit(list);
}
public static void Count3Quit(List list){
int countNum = 0;
Node node = list.head;
while(list.length > 0){
countNum ++;
if(countNum == 3){
countNum = 0;
list.deleteNode(node);
}
node = node.next;
}
print(list.head.id);
///print(list.tail.id);
}
public static void print(Object o){
System.out.println(o);
}
}
class Node{
int id;
Node prev;
Node next;
}
class List{
int length = 0;
Node head;
Node tail;
List(int n){
for(int i=0; i<n; i++){
addNode();
}
}
public void addNode(){
Node node = new Node();
if(length == 0){
head = tail = node;
print("The first Node added!");
}else{
head.prev = node;
node
版权声明:本文标题:长文慎点,Java学习笔记(四) 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://m.elefans.com/xitong/1727847988a1133318.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论