After-school assignment string encryption:
Design ideas:
1. Enter the English substring to encrypt str
2. Define the string length of the Num=str
3. Convert a string to a single character
4. Each character +3, move backwards by 3
5. Define STR1, multibyte the newly obtained word to str1, and get the encrypted English substring str1
6. Output encryption after the English sub-string str1
Source:
Import Java.util.Scanner;
public class Test {
public static void Main (string[] args) {
TODO auto-generated method stubs
Scanner input=new Scanner (system.in);
System.out.println ("Please enter the English substring to encrypt:");
String str;
int num=0;
Str=input.nextline ();
Num=str.length ();
Char A;
int num1=0;
String Str1=new string ();
for (int i=0;i<num;i++)
{
A=str.charat (i);
A= (char) (A+3);
Str1=str1+a;
}
SYSTEM.OUT.PRINTLN ("The Encrypted English substring is: \ n" +str1);
}
}
Results:
The hands of the brainstring.equals ()Method:
String.Equals() is used to determine whether the contents of two string objects are the same, and = = determines whether the references to two string instances are the same , that is, whether the first address is the same.
FinishingStringClass ofLength (),charAt (),GetChars (),replace (),toUpperCase (),toLowerCase (),Trim (),ToCharArray ()Instructions for use
Length () can be used to find string lengths.
CharAt () gets the character at the specified position.
GetChars () Gets a string from the specified position copied to the character array, such as s.getchars (0,5,chararray,0); Four the meaning of a parameter: 1. Span style= "font-family: ' Times New Roman ';" >2. The last character copied is subscript in the string. +1 3. 4. The copied character is placed in the character array starting with the subscript.
Replace () substring substitution, such as replace(old,new), with new strings instead of older strings.
toUpperCase (), toLowerCase () case conversion.
Trime () removes the Kinsoku space.
ToCharArray () converts a string object to a character array
Java post-class jobs