1. Run the following sample code Stringpool.javato see its output. How do I interpret this output? What can you sum up from it?
It can be concluded that the string connected with the plus sign and an entire string of the same code is true, and the new space is not, = = only the address and content are the same is true
and The string.equals () function determines whether the content is consistent.
2, 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 ideas: Enter the substring to encryptStr, defines the length of the string, converts the string to a single character, each character+3, move backwards3one, each character-3, move forward3One, definestr1, multibyte each new word tostr1after you get the encrypted English substringstr1, definestr2, multibyte each new word tostr2after that, get the decrypted English substringstr2, the output of the encrypted sub-stringstr1, output the decrypted substringstr2
Flow chart:
Code:
import javax.swing.*;
Public class Output
{
Public Static void Main (string[] args) {
String str = Joptionpane. Showinputdialog ("Please input the");
int n=0;
N=str.length ();
Char A, B;
int n1= 0;
String str1=new string ();
String str2=new string ();
for (int i=0;i<n;i++)
{
A=str.charat (i);// Gets the string at the specified position
B=str.charat (i);// Gets the string at the specified position
A= (char) (a+3);
b= (char) (b-3);
Str1=str1+a;
Str2=str2+b;
}
System. out. println ("The encrypted substring is : \ n"+str1);
System. out. println (" decrypted substring : \ n"+str2);
}
}
:
4. Method finishing
Length (): Gets the string length, which is an object in which the length property is contained, which is the long of the string, which can be obtained by using length () method in the String class.
CharAt (): gets the character at the specified position
GetChars (): gets the substring from the specified position copied into the character array (it has four parameters,1. The starting position of the copied character in the string 2. The last character to be copied is added 1 3 to the subscript in the string. Target character array 4. The copied character is placed in the character array starting subscript )
Replace (): substring substitution, by using the Replace () method of the string class, you can replace a character in the original string with the specified character and get a new string that is specifically defined as follows: public String replace (char Oldchar,char Newchar)
toUpperCase (), toLowerCase (): Case conversion, in the string class, provides two methods to implement the letter case conversion, their return value is the converted string, where toLowerCase () is used to change all uppercase letters in a string to lowercase letters, and Method toUpperCase () is used to change all lowercase letters in the string to uppercase letters.
Trim (): Remove the leading and trailing spaces, by using the trim () method of the String class, you can get a new string by removing the leading and trailing spaces of the string, the method is defined as follows: public string trim ()
ToCharArray (): converts a String object to a character array
05String string after class job