• java小程序(课堂作业04)


    请编写一个程序,使用上述算法加密或解密用户输入的英文字串要求设计思想、程序流程图、源代码、结果截图。

    1,设计思想:

    先输入索要加密的字符串由于此程序比较基础所以只考虑大写字母,然后用toCharArray()函数将字符串赋给一个char型数组,然后依次查询数组里元素如果是XYZ中的其中一个让其-23变成A,B,CASCII值然后强转成char型重新赋给对应的数组位置,其他的则直接+3再转,然后输出。

    2,流程图:

    ,

    3,源代码:

    import javax.swing.JOptionPane;
    public class JiaMi 
    {
    public static void main(String[] args)
    { 
    String s=JOptionPane.showInputDialog("请输入字符串:");
    char charArray[]=s.toCharArray();//将字符串转化成字符数组。
    for ( int i = 0; i < charArray.length; i++ )
    {
    //特殊情况,当字符为XYZ时转化成ABC
    if(charArray[i]=='X'||charArray[i]=='Y'||charArray[i]=='Z')
    {
    charArray[i]=(char)(charArray[i]-23);
    }
    //一般情况,将字符对应成ASCII码+3后再转化成字符。
    else
    {
    charArray[i]=(char)(charArray[i]+3);
    }
    }
    //将加密后的字符输出。
    JOptionPane.showMessageDialog(null, "加密后的字符串:"+String.valueOf(charArray));
    }
    }

    4,结果截图:

  • 相关阅读:
    进程与线程
    the art of seo(chapter seven)
    the art of seo(chapter six)
    the art of seo(chapter five)
    the art of seo(chapter four)
    the art of seo(chapter three)
    the art of seo(chapter two)
    the art of seo(chapter one)
    Sentinel Cluster流程分析
    Sentinel Core流程分析
  • 原文地址:https://www.cnblogs.com/chch157/p/7738944.html
Copyright © 2020-2023  润新知