1、字符串abcdefg,要求按逆序输出为gfedcba
public class Main {
public static void main(String[] args) {
StringBuffer buf = new StringBuffer("abcdefg");
buf = buf.reverse();
System.out.println(buf.toString());
}
}
2、使用字符串的正则判断是否全部由数字组成
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class JA V A {
public static void main(String[] args) {
String regEx = "\\D+";
Scanner in = new Scanner(System.in);
while (in.hasNext()) {
String str = in.next();
Pattern p = http://www.doczj.com/doc/8bc543e86294dd88d0d26b1f.htmlpile(regEx);
Matcher m = p.matcher(str);
if (!m.find()) {
System.out.println("输入的字符串全是数字");
} else {
System.out.println("输入的字符串不全是数字");
}
}
}
}
3、把当前日期转换成yyyy年MM月dd日
import java.text.SimpleDateFormat;
import java.util.Date;
public class JA V A {
public static void main(String[] args) {
SimpleDateFormat sf = new SimpleDateFormat("yyyy年MM月dd日"); Date d = new Date();
String s = sf.format(d);
System.out.println(s);
}
}