Java Job 04 (Hands-on brain)

Source: Internet
Author: User

1. the ancient Roman Emperor Caesar had used the following methods to encrypt military information during the war:

Please write a program, using the above algorithm to encrypt or decrypt the user input of the English string requirements design ideas, program flowchart, source code, results.

Design idea: First the user enters a string, prompts the user to choose the encryption or the decryption string, the design program completes the function, the encryption is the string each bit moves backwards three bits to replace that letter, the decryption moves forward three bits, finally outputs the new string.

Program Flowchart:

Source:

Results:

2. Please review the implementation code of the string.equals () method and learn how to implement it.

Answer: Equals is only the same as the comparison value
and = = is a comparison of two variables is not the same variable, also is said
To see if these two variables are references to the same address,
Only two variables of the same reference address in Java are considered = =.

3. Organize string class Span style= "font-family: ' Times New Roman ';" >length () , charat ()   getchars () , replace () Span style= "font-family: the song Body;" >,   touppercase ()   tolowercase () , trim () , tochararray () use notes, read notes published to the blog Park.

Length (): returns the lengths of the strings. The length is equal to the number of strings in the Unicode code unit

charAt (): a method that retrieves a string instance of a character under a specific index . The charAt () method returns the char at the specified index position values.

getChars (): copies the character from this string to the target character array. Example:

String str = "Abcdefghikl";
char[] ch = new CHAR[8];
Str.getchars (2,5,ch,0);
is from the second letter of STR has been copied to the fifth , a total of 3 characters , from Ch The first one to start accepting

replace ():Public String replace (char OldChar, char Newchar)returns a new string that is passed by using theNewcharReplace all occurrences of this stringOldCharto get. IfOldCharin thisStringobject does not appear in the sequence of characters represented by theStringthe reference to the object. Otherwise, create a newStringobject, which represents the sequence of characters in addition to all theOldCharare replaced by theNewchar, with thisStringobject represents the same sequence of characters.

touppercase (): converts all characters in this string into uppercase

toLowerCase (): Converts all characters in this string to lowercase

Trim (): The method returns a copy of the calling string object, but all the starting and trailing spaces are deleted

ToCharArray (): converts this data into a character array

Java Job 04 (Hands-on brain)

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.