To convert a string into a character array
First letter judgment
Idea: How to get the first letter
ARR[0] The first element of the array is the first letter
A number evaluates to True to a number false to a non-numeric
"0123456789". Contains (arr[0]+ "");
The alphabet determines that one of them is a letter.
(arr[0]>= ' z ' &&arr[0]<= ' a ') | | (arr[0]>= ' Z ' &&arr[0]<= ' A ')
Other index positions can be judged simply by traversing the array
Note: When writing this code, it should be a judgment to write the verification, after all the interpretation has been written, they can be logically connected to
/* Write a program that verifies the user name and detects if the user name entered by the keyboard is legal
Requirement: The user name must be a letter between 6-10 bits and cannot start with a number */
public class Demo20 {
public static void Main (string[] args) {
Scanner sc = new Scanner (system.in);
System.out.println ("Please enter your account");
String str = sc.nextline ();
char[] arr = Str.tochararray ();
Boolean B = "0123456789". Contains (Arr[0] + "");
if (b) {
SYSTEM.OUT.PRINTLN ("Cannot begin with a number");
} else {
Judging length
if (! ( Arr.length >= 6 && arr.length <= 10)) {
SYSTEM.OUT.PRINTLN ("Incorrect input length");
} else {
Judging is not the letter
for (char C:arr) {
if (! ( (c >= ' a ' && c <= ' z ') | | (c >= ' A ' && C <= ' Z '))) {
System.out.println ("Please enter the letter");
Return
}
}
SYSTEM.OUT.PRINTLN ("Login Successful");
}
}
}
}
Java Basic Phase Judgment summary of password or account character numbers