public class HelloWorld {
public static void main(String[] args) {
String fileName = "HelloWorld.jav";
String email = "laurenyang@imooc.com";
int index =fileName.lastIndexOf(".");
String prefix = fileName.substring(index);
if ( index > 0 && (prefix.equals (".java"))) {
System.out.println("Java文件名正确");
} else {
System.out.println("Java文件名无效");
}
int index2 = email.indexOf("@");
int index3 = email.indexOf('.');
if (index2 != -1 && index3 > index2) {
System.out.println("邮箱格式正确");
} else {
System.out.println("邮箱格式无效");
}
}
}
String prefix =fileName.toString(index+1,fileName.length);这段代码啥意思了?
因为
index的下标从0开始