Java 做一个加密程序,我得到一个sytnax错误,但我不知道为什么
目前,我正在尝试制作一个基本程序,它接受任何字符串的输入,例如一个句子或一个段落,它接受每个字母,并将其转换为3个字符的代码一旦我开始工作,我假设我应该能够做相反的事,让它接受3位数的代码并将其转换回文本,无论如何,当我试图编译程序来测试它时,我得到了一个错误。我已将问题标记在下面。此外,一旦我得到的程序工作,我想为它做一个图形用户界面,你把输入,它显示输出后,你点击一个按钮,但由于我刚刚开始,这似乎是一个很好的,但对我来说,如果你知道任何好的教程,请让我知道Java 做一个加密程序,我得到一个sytnax错误,但我不知道为什么,java,encryption,Java,Encryption,目前,我正在尝试制作一个基本程序,它接受任何字符串的输入,例如一个句子或一个段落,它接受每个字母,并将其转换为3个字符的代码一旦我开始工作,我假设我应该能够做相反的事,让它接受3位数的代码并将其转换回文本,无论如何,当我试图编译程序来测试它时,我得到了一个错误。我已将问题标记在下面。此外,一旦我得到的程序工作,我想为它做一个图形用户界面,你把输入,它显示输出后,你点击一个按钮,但由于我刚刚开始,这似乎是一个很好的,但对我来说,如果你知道任何好的教程,请让我知道 import java.util.
import java.util.Scanner;
import java.util.*;
class test {
private static Scanner inp;
public static void main(String[] args) {
Map <Character, String> encryptionMappings = new HashMap<>();
encryptionMappings.put('a',"{qaz}");
encryptionMappings.put('b',"{wsx}");
encryptionMappings.put('c',"{edc}");
encryptionMappings.put('d',"{rfv}");
encryptionMappings.put('e',"{tgb}");
encryptionMappings.put('f',"{yhn}");
encryptionMappings.put('g',"{ujm}");
encryptionMappings.put('h',"{ik,}");
encryptionMappings.put('i',"{ol>}");
encryptionMappings.put('j',"{p;?}");
encryptionMappings.put('k',"{[']}");
encryptionMappings.put('l',"{qwe}");
encryptionMappings.put('m',"{asd}");
encryptionMappings.put('n',"{zxc}");
encryptionMappings.put('o',"{rty}");
encryptionMappings.put('p',"{fgh}");
encryptionMappings.put('q',"{vbn}");
encryptionMappings.put('r',"{yui}");
encryptionMappings.put('s',"{hjk}");
encryptionMappings.put('t',"{nm,}");
encryptionMappings.put('u',"{iop}");
encryptionMappings.put('v',"{qaw}");
encryptionMappings.put('w',"{sxz}");
encryptionMappings.put('x',"{red}");
encryptionMappings.put('y',"{cvf}");
encryptionMappings.put('z',"{ytg}");
encryptionMappings.put('A',"{hnb}");
encryptionMappings.put('B',"{iuj}");
encryptionMappings.put('C',"{kml}");
encryptionMappings.put('D',"{opl}");
encryptionMappings.put('E',"{wom}");
encryptionMappings.put('F',"{wsv}");
encryptionMappings.put('G',"{ths}");
encryptionMappings.put('H',"{imv}");
encryptionMappings.put('I',"{ybf}");
encryptionMappings.put('J',"{cja}");
encryptionMappings.put('K',"{thw}");
encryptionMappings.put('L',"{maz}");
encryptionMappings.put('M',"{pqa}");
encryptionMappings.put('N',"{zwl}");
encryptionMappings.put('O',"{;ld}");
encryptionMappings.put('P',"{'d;}");
encryptionMappings.put('Q',"{;ny}");
encryptionMappings.put('R',"{;ws}");
encryptionMappings.put('S',"{c/.}");
encryptionMappings.put('T',"{%@^}");
encryptionMappings.put('U',"{/mc}");
encryptionMappings.put('V',"{uka}");
encryptionMappings.put('W',"{zby}");
encryptionMappings.put('X',"{&hd}");
encryptionMappings.put('Y',"{&hw}");
encryptionMappings.put('Z',"{^#^}");
encryptionMappings.put('0',"{$g%}");
encryptionMappings.put('1',"{^@%}");
encryptionMappings.put('2',"{142}");
encryptionMappings.put('3',"{243}");
encryptionMappings.put('4',"{089}");
encryptionMappings.put('5',"{756}");
encryptionMappings.put('6',"{423}");
encryptionMappings.put('7',"{312}");
encryptionMappings.put('8',"{145}");
encryptionMappings.put('9',"{187}");
encryptionMappings.put('~',"{)*(}");
encryptionMappings.put('`',"{$#%}");
encryptionMappings.put('!',"{!^#}");
encryptionMappings.put('@',"{@^&}");
encryptionMappings.put('#',"{^@&}");
encryptionMappings.put('$',"{!?*}");
encryptionMappings.put('%',"{^<+}");
encryptionMappings.put('^',"{+$$}");
encryptionMappings.put('&',"{!!*}");
encryptionMappings.put('*',"{((%}");
encryptionMappings.put('(',"{*&^}");
encryptionMappings.put(')',"{$%^}");
encryptionMappings.put('_',"{&#^}");
encryptionMappings.put('-',"{<>?}");
encryptionMappings.put('=',"{:'^}");
encryptionMappings.put('{',"{%%G}");
encryptionMappings.put('}',"{$$$}");
encryptionMappings.put('[',"{***}");
encryptionMappings.put(']',"{:::}");
encryptionMappings.put(':',"{#$%}");
encryptionMappings.put('|',"{?H*}");
encryptionMappings.put(';',"{B&&}");
encryptionMappings.put('"',"{@gs}");
encryptionMappings.put('?',"{^gl}");
encryptionMappings.put('/',"{@gn}");
encryptionMappings.put('<',"{%TG}");
encryptionMappings.put('>',"{5%5}");
encryptionMappings.put(',',"{yty}");
encryptionMappings.put('.',"{ggg}");
inp = new Scanner(System.in);
System.out.println("Input Password");
int n = inp.nextInt();
if(n!=234) {
System.out.println("Denied Acess");
} else {
System.out.print("Password Accepted"
+ " ");
System.out.print("Input Text to encrypt: ");
String m = inp.next();
String encryptMe = "He";
StringBuilder builder = new StringBuilder();
您正试图对对象调用一个方法,但缺少需要遵循
toCharArray
的空()
。有些语言允许省略空括号,但Java不是其中之一。你应使用:
for (Character c : encryptMe.toCharArray()) {
builder.append(encryptionMappings.get(c));
}
一个好的IDE(Eclipse、Intellij IDEA、Netbeans等)将帮助您在学习的过程中捕捉这些语法错误 我看到你开始了。但有一个提示:这是非常基本的东西。在Java对象中,只有字段或方法。这就是我昨天提到阅读所有javadoc的原因。然后您会注意到toCharArray必须是一个方法调用。。。因此需要括号。如果quora不明白,你应该先学习一些关于这些基础知识的教程。我刚刚在那个答案中修改了我的示例代码。顺便说一句,我不知道你在你给我的代码中把输出和输入变量分配给了什么。看起来liek“encryptme”是输入和“encrypt”是输出,但当我这样设置它时,它不工作,并且错误该方法在中定义,并且我刚刚验证了代码对我有效。我不知道你为什么会犯这个错误,除非上面还有一个错误。在Java中,始终尝试解决最早的编译问题,因为它可能会影响以下问题。我现在可以使用它了。感谢您的帮助,现在我只需要让它正确地输出代码
for (Character c : encryptMe.toCharArray()) {
builder.append(encryptionMappings.get(c));
}