我想出了下面的代码。设法解决了大多数错误,除了与地图相关的错误。
我知道下面的代码行属于 C++。几天以来尝试了很多将其转换为JAVA,但无法找到方法:
下面是 C++ 中的代码行
map<Character,Integer> enc = new map<Character,Integer>();
注意:将上述语法改为HashMap/Map并导入Java.Util后,以下代码中标有3星的代码行显示以下错误“表达式的类型必须是数组类型,但它解析为Map”
1) enc[input.charAt(i)] = i; 2) int pos = enc[msg.charAt(i) - 32]; 3) int pos = enc[msg.charAt(i)];
// 此函数将破译任何输入消息
public static String ABC(String msg, String input)
{
// Hold the position of every character (A-Z) from encoded string
map<Character,Integer> enc = new map<Character,Integer>();
for (int i = 0; i < input.length(); i++)
{
***enc[input.charAt(i)] = i;***
}
String decipher = "";
// This loop deciphered the message.
// Spaces, special characters and numbers remain same.
for (int i = 0; i < msg.length(); i++)
{
if (msg.charAt(i) >= 'a' && msg.charAt(i) <= 'z')
{
***int pos = enc[msg.charAt(i) - 32];***
decipher += plaintext.charAt(pos);
}
else if (msg.charAt(i) >= 'A' && msg.charAt(i) <= 'Z')
{
***int pos = enc[msg.charAt(i)];***
decipher += plaintext.charAt(pos);
}
else
{
decipher += msg.charAt(i);
}
}
return decipher;
}
元芳怎么了
小唯快跑啊
米琪卡哇伊
随时随地看视频慕课网APP
相关分类