---string for homework after class

Source: Internet
Author: User

I. Homework after class one

1. design idea: According to test instructions, first prompt for the action to be done: decrypt or encrypt , then enter a string, using the charat () method to connect the changed letter to the result, encrypt: Before 23 uppercase and lowercase letters +3 , after 3 -23 char decryption: after 23 uppercase and lowercase letters -3 3 +23

2. program Flowchart:

3. Source code:

Package t4;//Hu Jian, 2016.10.25//string encryption import Java.util.scanner;public class Test {public static void main (String args[]) {SCA Nner N = new Scanner (system.in);//Input System.out.print ("Enter the action to be performed (1. Encryption, 2 decryption):"); int choose = N.nextint (); String result= ""; char temp;if (choose = = 1)//encryption {System.out.print ("Please enter string:"); String wen = N.next (); for (int i = 0;i < Wen.length (); i++) {if (Wen.charat (i) > && wen.charat (i) < 88) | | (Wen.charat (i) > 98 && wen.charat (i) < 120)) Temp= (char) (Wen.charat (i) + 3); else if ((Wen.charat (i) > && wen.charat (i) < 91) | | (Wen.charat (i) > 119 && Wen.charat (i) < 123)) Temp= (char) (Wen.charat (i)-23°c); Else{system.out.println ("Incorrect middle input!"); break;} result + = temp;} SYSTEM.OUT.PRINTLN ("Results after encryption:" + result);} else if (choose = = 2)//Decrypt {System.out.print ("Please enter string:"); String wen = N.next (); for (int i = 0;i < Wen.length (); i++) {if (Wen.charat (i) > && wen.charat (i) < 91) | | (Wen.charat (i) > && wen.charat (i) < 123)) TeMp= (char) (Wen.charat (i)-3), Else if ((Wen.charat (i) > && wen.charat (i) < 68) | | (Wen.charat (i) > && wen.charat (i) < 100)) Temp= (char) (Wen.charat (i) + +); Else{system.out.println ("Incorrect middle input!"); break;} result + = temp;} SYSTEM.OUT.PRINTLN ("Decrypted result is:" + result);} ELSESYSTEM.OUT.PRINTLN ("Wrong input! "); N.close ();}}

4. Results:

Second, after-school homework two

---string for homework after class

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.