Java Classroom Encryption

Source: Internet
Author: User

1. String encryption

Design ideas:

Each character can be converted to an integer type, can also convert the integer type to a character type, so that we in the encryption time due to push 3 backward , so we can convert the character to shaping, and then add 3, after the operation of the variable into a character after the output, you can implement string encryption.

Program Flowchart:

input string -"break the string into characters-" character to reshape-"reshape plus 3-" Convert to Character-"output."

Source:

Import Java.util.Scanner;

public class Miwen {

public static void Main (String args[])

{

char temp;

int b;

SYSTEM.OUT.PRINTLN ("Please input string:");

Scanner Scanner = new Scanner (system.in);

String a = Scanner.next ();

int N=a.length ();

for (int i=0;i<n;i++)

{if (A.charat (i) < ' x ')

{Temp=a.charat (i);

b= (int) temp;

B=b+3;}

Else

{Temp=a.charat (i);

b= (int) temp;

b=b-23;}

temp = (char) b;

SYSTEM.OUT.PRINTLN (temp);

}

}

}

2.string.equals () method

"= =" Determines whether two objects are identical, i.e. content and address, while equals () compares content only, such as judging S1 and S2 content format s1.equals (S2);

3. Defragment the String class length (), CharAt (), GetChars (), replace (), toUpperCase (), toLowerCase (), Trim (), ToCharArray () usage instructions

Length () is used to find the lengths of the strings, and the return value is the length of the string.

CharAt () takes the character of the string at a location, starting with 0, as the char type

GetChars () copies the characters in this string to the target character array

Replace () replaces the element or substring in the original string. Returns the replaced string

toUpperCase () to capitalize characters in string strings

toLowerCase () to lowercase characters in string strings

Trim () The header of the stripped string is a space

ToCharArray () Converts a string to a character array

Java Classroom Encryption

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.