Java basic notes (1), java basic notes

Source: Internet
Author: User

Java basic notes (1), java basic notes

After learning jsp, let's go back and look at the basics. We found that a lot of things are clearly simple, just like learning from the beginning.

1. Determine whether the input number is a four-digit integer.

First, use counter. nextInt () to receive the input number. If it is not an integer, an error is returned. You can use try catch to control the feedback action when the input is invalid;

Then convert the input number into a String, such as int I = 3323; String iStr = I + "; then you can use iStr. length to determine whether the input number is a four-digit number.

2. Convert the input lowercase letters to uppercase letters.

First, the input letter is received as a string using in. next (), and the character (int index) is extracted using the string method charAt (int index). Then, the uppercase and lowercase letters can be directly subtracted.

The Ascii code difference is 32, and the forced conversion to the char type is good. Example:

Running in = new Processing (System. in );

String xiaoxie = in. next ();
Char xx = xiaoxie. charAt (0 );
Char daxie = (char) (xx-32 );

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.