目录
488-Date介绍
IDEA里面的properties是set/get方法
489-Date应用实例
490-Calendar介绍
491-Calendar应用实例
Calendar c = Calendar.getInstance();
492-第三代日期使用
493-第三代日期方法
494-String翻转
package chapter13.homework;
/**
* @author LuHan
* @version 1.0
*/
public class Homework01 {
public static void main(String[] args) {
String str = "abcdef";
System.out.println(str);
str = reverse(str, 1, 4);
System.out.println(str);
}
public static String reverse(String str,int start,int end){
char[] chars=str.toCharArray();
char temp=' ';
for(int i=start,j=end;i<j;i++,j--){
temp=chars[i];
chars[i]=chars[j];
chars[j]=temp;
}
return new String(chars);
}
}
495-注册处理题
package chapter13.homework;
/**
* @author LuHan
* @version 1.0
*/
public class Homework02 {
public static void main(String[] args) {
String name = "hl";
String pwd = "123456";
String email = "[email protected]";
try {
userRegister(name, pwd, email);
System.out.println("注册成功!!!");
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
public static void userRegister(String name, String pwd, String email) {
int userLength = name.length();
if (!(userLength >= 2 && userLength <= 4)) {
throw new RuntimeException("用户名长度应为2、3、4");
}
if (!(pwd.length() == 6 && isDigital(pwd))) {
throw new RuntimeException("密码长度为6,要求全是数字");
}
int i = email.indexOf('@');
int j = email.indexOf(".");
if (!(i > 0 && j > i)) {
throw new RuntimeException("邮箱不对");
}
}
public static boolean isDigital(String str) {
char[] chars = str.toCharArray();
for (int i = 0; i < chars.length; i++) {
if (chars[i] < '0' || chars[i] > '9') {
return false;
}
}
return true;
}
}
496-字符串统计
package chapter13.homework;
/**
* @author LuHan
* @version 1.0
*/
public class Homework03 {
public static void main(String[] args) {
String str = "han shun ping";
printName(str);
}
public static void printName(String str){
if(str==null){
System.out.println("str 不能为空");
return;
}
String[] names=str.split(" ");
if(names.length!=3){
System.out.println("输入的字符串格式不对");
}
String format=String.format("%s,%s,%c",names[2],names[0],names[1].toUpperCase().charAt(0));
System.out.println(format);
}
}
497-String内存布局测试题
a.equals(b),false,是因为这个对象并没有重写equals,比较的是两个对象是否相等
标签:String,chapter13,System,println,day17,static,str,Date,public From: https://blog.csdn.net/hlllllllhhhhh/article/details/142053615