Import Java.util.Scanner;
public class Stringtest {
public static void Main (string[] args) {
int back = 1;
Scanner input =new Scanner (system.in);
do{//Set the loop method until the input is correct
System.out.print ("Java file name:");
String str1 =input.next ();
System.out.print ("Please enter your e-mail:");
String str2= Input.next ();
int m = str2.indexof (' @ '); Check if there is an @ character and use M to receive the index @ appears
int n = str2.indexof ('. '); Check if there is a '. ' Characters, which are received by N. The index that appears
String STR3 = str1.substring (Str1.indexof (".") +1); Returns the. Trailing substring, +1 is to not include the character '. '
if (!str3.equals ("Java")) {
SYSTEM.OUT.PRINTLN ("Java file name is illegal! ");
}
else{
SYSTEM.OUT.PRINTLN ("Java filename is legal! ");
}
if (! ( M! = -1&& N! = -1&& m <n)) {//if M and N have one for-1, that must be illegal, m and N if valid, the position of M must be smaller than n
System.out.println ("The mailbox name is not legal! ");
}else{
SYSTEM.OUT.PRINTLN ("Legal mailbox name! "); break;
}
}while (back!=3);
}
}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Determine if a Java file and mailbox format is legitimate