String.Equals () method:
is to Compare the contents of a string that is encapsulated by A String object, that is, if the contents of the string that are encapsulated by two string objects are the same (including the same case), then equals ( ) method will return true.
length() of the String class ,char (), GetChar (), replace (), toUpperCase (), toLowerCase (), Trim (), ToCharArray () instructions for use
Length () to find string lengths
char () gets the character at the given index
GetChar () character conversion array
Replace ()
toUpperCase () converts all characters in a string to uppercase
toLowerCase () converts all characters in a string to lowercase
Trim () remove spaces at the beginning and end of a character
ToCharArray () converts this string to a new character array
2. The ancient Roman Emperor Caesar had used the following methods to encrypt military information during the war:
Write a program that uses the above algorithm to encrypt or decrypt the user-entered English string.
Import Javax.swing.JOptionPane;
public class Jiami {
public static void Main (string[] args) {
TODO auto-generated method stubs
String Www=joptionpane.showinputdialog ("Please enter a string:");
Char Chararray[]=www.tochararray ();
for (int i=0;i<chararray.length;i++)
{
if (chararray[i]== ' X ' | | chararray[i]== ' Y ' | | chararray[i]== ' Z ')
Chararray[i]= (char) (CHARARRAY[I]-23);
Else
Chararray[i]= (char) (CHARARRAY[I]+3);
}
Joptionpane.showmessagedialog (NULL, "Encrypted string:" +string.valueof (Chararray));
}
}
Screenshot:
Methods and cryptographic programs for string classes in Java