Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/328.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java-为什么是;007F“;打印出来?_Java_System.out - Fatal编程技术网

Java-为什么是;007F“;打印出来?

Java-为什么是;007F“;打印出来?,java,system.out,Java,System.out,下面的代码是根据“secret”消息的ASCII值进行解密的:mmZ\\dxZmx]Zpgy 应该打印出来的内容:“黎明进攻!” 它当前打印的内容:“在007F黎明攻击007F?” 所以基本上,现在x=“007F”和 y=“?” 我需要x=SPACE或“”,以及y=“!” 谢谢你抽出时间 public class decryption { public static void main(String[] args) { String secretMessage =

下面的代码是根据“secret”消息的
ASCII
值进行解密的:mmZ\\dxZmx]Zpgy

应该打印出来的内容:“黎明进攻!”

它当前打印的内容:“在007F黎明攻击007F?”

所以基本上,现在
x=“007F”
y=“?”

我需要
x=SPACE
或“”,以及
y=“!”

谢谢你抽出时间

public class decryption
{
    public static void main(String[] args)
    {
        String secretMessage = ":mmZ\\dxZmx]Zpgy";
        System.out.println(decryption(secretMessage, 88));
    }//end main

    public static String decryption(String s, int n)
    {
        int originalChar, decryptedChar;
        String message = "";
        char c;

        for(int i = 0; i < s.length(); ++i)
        {
            c = s.charAt(i);
            decryptedChar = (int)c;
            if(decryptedChar + n > 126)
               originalChar = 32 + ((decryptedChar + n) - 113);
                  else
                     {originalChar = decryptedChar + n;
                     c = c;}
            message = message + (char)originalChar;
        }//end for loop
        return message;
    }//end method
 }//end class
公共类解密
{
公共静态void main(字符串[]args)
{
字符串secretMessage=“:mmZ\\dxZmx]Zpgy”;
System.out.println(解密(secretMessage,88));
}//端干管
公共静态字符串解密(字符串s,int n)
{
int originalChar,decryptedChar;
字符串消息=”;
字符c;
对于(int i=0;i126)
原始字符=32+((解密字符+n)-113);
其他的
{originalChar=decryptedChar+n;
c=c;}
消息=消息+(字符)原始字符;
}//循环结束
返回消息;
}//结束方法
}//末级

我把它修好了。问题是ASCII值>126是不正确的,所以简单地减去95就可以修复decyrption

公共类解密
{
公共静态void main(字符串[]args)
{
字符串secretMessage=“:mmZ\\dxZmx]Zpgy”;
System.out.println(解密(secretMessage,88));
}//端干管
公共静态字符串解密(字符串s,int n)
{
int originalChar,decryptedChar;
字符串消息=”;
字符c;
对于(int i=0;i126)
原始字符=32+((解密字符+n)-113);
其他的
{originalChar=decryptedChar+n;
c=c;}
如果(原始图像>126)
originalChar=originalChar-95;
消息=消息+(字符)原始字符;
}//循环结束
返回消息;
}//结束方法

}//end class
使用
(char)originalChar
强制转换类型时,检查是否存在未签名的有符号转换。