有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java为什么这是一个“找不到符号”错误?

我正在完成我的项目,但一直遇到这个错误。我不明白,因为置换数据是另一个具有静态字符串[][]的类,我正在检查元素x[0]是否在置换数据中,但我的编译器一直将置换数据识别为变量而不是类。。。。我现在在我的旋翼班里

转子。java:90:错误:找不到符号

for (String[] x : PermutationData.ROTOR_SPECS) {
                  ^
symbol: variable PermutationData
location: class Rotor
        if (type() == x[0]) {
            Index1 = toIndex(x[1].charAt(p));

这是我的排列数据。java类

class PermutationData {

/** The names and definitions of the rotors and reflectors in M4.  The
 *  first string in each entry is the name of a rotor or reflector.  The
 *  second is a 26-character string whose first character is the mapping
 *  (when the rotor is at the 'A' setting), of 'A' in the right-to-left
 *  direction, whose second is that of 'B', etc.
 *
 *  The third entry, if present, is the inverse of the
 *  second---the left-to-right permutation of the rotor.  It is
 *  not present for reflectors.
 *
 *  The fourth entry, if present, gives the positions of the
 *  notches. These are the settings of the rotors just before the
 *  wheels advanced (wheels advance before a character is
 *  translated).  Other written accounts of the Enigma generally
 *  show instead the character settings just after a character is
 *  coded (e.g., 'R', rather than 'Q', or 'A' rather than 'Z').
 *  The entry is absent in rotors that do not advance. */

static final String[][] ROTOR_SPECS = {
    { "I", "EKMFLGDQVZNTOWYHXUSPAIBRCJ", "UWYGADFPVZBECKMTHXSLRINQOJ",
      "Q" },
    { "II", "AJDKSIRUXBLHWTMCQGZNPYFVOE", "AJPCZWRLFBDKOTYUQGENHXMIVS",
      "E" },
    { "III", "BDFHJLCPRTXVZNYEIWGAKMUSQO", "TAGBPCSDQEUFVNZHYIXJWLRKOM",
      "V" },
    { "IV", "ESOVPZJAYQUIRHXLNFTGKDCMWB", "HZWVARTNLGUPXQCEJMBSKDYOIF",
      "J" },
    { "V", "VZBRGITYUPSDNHLXAWMJQOFECK", "QCYLXWENFTZOSMVJUDKGIARPHB",
      "Z" },
    { "VI", "JPGVOUMFYQBENHZRDKASXLICTW", "SKXQLHCNWARVGMEBJPTYFDZUIO",
      "ZM" },
    { "VII", "NZJHGRCXMYSWBOUFAIVLPEKQDT", "QMGYVPEDRCWTIANUXFKZOSLHJB",
      "ZM" },
    { "VIII", "FKQHTLXOCBJSPDZRAMEWNIUYGV", "QJINSAYDVKBFRUHMCPLEWZTGXO",
      "ZM" },
    { "BETA", "LEYJVCNIXWPBQMDRTAKZGFUHOS", "RLFOBVUXHDSANGYKMPZQWEJICT" },
    { "GAMMA", "FSOKANUERHMBTIYCWLQPZXVGJD", "ELPZHAXJNYDRKFCTSIBMGWQVOU" },
    { "B", "ENKQAUYWJICOPBLMDXZVFTHRGS" },
    { "C", "RDOBJNTKVEHMLFCWZAXGYIPSUQ" }
};

}


共 (3) 个答案

  1. # 1 楼答案

    除了@alfasin给出的答案外,请确保已导入排列数据

  2. # 2 楼答案

    如果ROTOR_SPECS确实是一个方法,那么应该使用括号来调用它:PermutationData.ROTOR_SPECS()

    否则编译器会认为它是一个变量

  3. # 3 楼答案

    我认为你的排列数据。java类具有默认级别的包访问权限,您可以从其他包调用它。因为这个排列数据。无法访问java类

    请整理数据。java public可以解决您的问题

    另一件事是,ROTOR_SPECS是String[]类型的变量。所以你可以先把它存储在程序中的某个地方,然后把它分配给其他变量,然后检查它是否存在

    试着运行这个。它正在发挥作用

    for (String[] x : PermutationData.ROTOR_SPECS) {  
                 System.out.println(x[0]);
    }