Java Basic Phase Judgment summary of password or account character numbers

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.