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