Methods and cryptographic programs for string classes in Java

Source: Internet
Author: User

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

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.