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 );