加密问题
Posted 程序咖啡
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了加密问题相关的知识,希望对你有一定的参考价值。
程序设计思想
字符串的加密是对每个字符进行加3操作,解密是减三操作
程序源码
import java.util.Scanner; public class JiaMi { public static void main(String[] args) { Scanner input=new Scanner(System.in); int choose=0; String s1=null,s2; System.out.println("请选择:\\n1.加密\\n2.解密"); choose=input.nextInt(); s2=input.nextLine(); if(choose==1) { System.out.println("请输入需要加密的字符串"); s1=input.nextLine(); for(int i=0;i<s1.length();i++) { System.out.print((char)(s1.charAt(i)+3)); } } else { System.out.println("请输入需要解密的字符串"); s1=input.nextLine(); for(int i=0;i<s1.length();i++) { System.out.print((char)(s1.charAt(i)-3)); } } } }
程序流程图
运行结果截图
以上是关于加密问题的主要内容,如果未能解决你的问题,请参考以下文章