java filename judgment practice

the HelloWorld class {public
public static void main (String [] args) {
// file name of the Java
String fileName = "HelloWorld.java";
// mailbox
String In Email = "[email protected]";

// file name is determined .java is correct: a legal file name should end with .java
/ *
reference steps:
1, obtain the file name in the last occurrence position number. ""
2, according to the position number, access the file suffix. ""
3, judgment " . "No file extensions and location
* /
. // get the location of the last occurrence of the file name" "No.
int index = fileName.lastIndexOf ( '.');

// get the file suffix
String prefix = fileName.substring ( +. 1 index, FileName.Length ());

// number determination must be included, and can not appear in the first place, while the suffix "Java". ""
IF (-1 = index index = 0 && && prefix.equals!! ( "Java")) {
the System.out.println ( "Java correct filename");
} the else {
System.out.println ( "the Java file name is invalid");
}

// determine whether the correct mailbox format: legitimate mailbox name must contain at least "@" and "@" is before "."
/ *
Reference steps:
1, obtain the location of the file name "@" symbol
2, get mailbox "." position No.
3, judgment must contain "@" sign, and "@" must "." before
* /
// Get position mailbox "@" symbol
int index2 = email.indexOf ( '@ ');

"." // Get position mailbox number
int = Index3 email.indexOf (' ');.

// Analyzing must contain "@" sign, and "@" must precede "."
IF (index2! && Index3 -1 => index2) {
System.out.println ( "correct mailbox format");
} the else {
System.out.println ( "invalid mailbox format");
}
}
}

Guess you like

Origin www.cnblogs.com/fengch/p/11419781.html