无法识别符号output.print()

时间:2012-08-07 19:34:35

标签: java printing bufferedreader

我的代码由于某种原因无法识别打印。

它给我错误:找不到符号 - :方法print(java.lang.String)

它处理了我制作的另一个代码,但它似乎讨厌这个......

21        System.out.print("What is the input file name? ");
22        String input = console.next();
23        FileInputStream fstream = new FileInputStream("/Users/steph/Desktop/Programming/!6 Problem Set TUES/PartB/6/" + input); //becomes input
24        BufferedReader in = new BufferedReader(new InputStreamReader(fstream));
25        System.out.print("What is the output file name? ");
26        String output = new Scanner(System.in).next();
27  
28        char str = input.charAt(0);
29        while (str == 0) {
30          System.out.println (str);
31        }
32        in.close();
35  
36        if (i == 1) {
37          String result = caesarEncipher(input, output, in, shift);
38          System.out.println("DONE!");
39        }
40  
41        if (i == 2) {
42          String result = caesarDecipher(input, output, in, shift);
43          System.out.println("DONE!");
44        }
45  
46          str = input.charAt(0);
47          while (str == 0) {//DON'T WANT THAT B.C LIKELY STICK str AT 0...
48            System.out.println (str);
49          }
50          in.close();
51      }


59    public static String caesarEncipher (String input, String output, BufferedReader in, int shift)
60      throws FileNotFoundException, IOException {
61  
62        int [] abc = new int [25];


83        output.print(abc[i] + "\n");
84        
85        while (shift < 0) { //move forward (a->b, b->c, etc.); stop when all shifted
86          for (int j = 0; j < shift; j++) {
87            int w = abc[0];
88            i = 0;
89          }
90          for (i = 0; i < (len - 1); i++)
91            abc[i] = abc[i+1];
92        }
93  
94        while (shift > 0) { //move backwards (a->z, b->a, etc.); stop when all shifted
95          for (int j = 0; j < shift; j++) {
96            int w = abc[len-1];
97            i = 0;
98            for (i = len-1; i > shift - 1; i--)
99            abc[i] = abc[i-1];
100         abc[i] = w;
101       }
102     }
103 

107     for (int x = 0; x < len; x++)
108       output.print(abc[x] + " ");
109   }
110 

111   public static String caesarDecipher (String fileName, String output, BufferedReader in, int shift)
112     throws FileNotFoundException, IOException {
113 
114       int [] abc = new int [25];
115 

135       output.print(abc[i] + "\n");
136       while (shift < 0) { //move forward (a->b, b->c, etc.); stop when all shifted
137         for (int j = 0; j < shift; j++) {
138           int w = abc[0];
139           i = 0;
140         }
141         for (i = 0; i < (len - 1); i++)
142           abc[i] = abc[i+1];
143       }
144 
145       while (shift > 0) { //move backwards (a->z, b->a, etc.); stop when all shifted
146         for (int j = 0; j < shift; j++) {
147           int w = abc[len-1];
148           i = 0;
149           for (i = len-1; i > shift - 1; i--)
150             abc[i] = abc[i-1];
151           abc[i] = w;
152         }
153       }

157 
158       for (int x = 0; x < len; x++)
159         output.print(abc[x] + " ");

在第83,108,135和159行,所有人都说同样的话:
   找不到标志    symbol:方法print(java.lang.String)

1 个答案:

答案 0 :(得分:1)

因此,您遇到in问题的原因是您在一个方法中将其声明为局部变量,但尝试使用其他方法访问它(您可以在大量代码之前看到此问​​题)在编辑中删除)。如果你想在任何地方使用它,那就把它变成一个字段。

至于output的问题,如果你看第123行,output有一个字符串,而不是一个PrintStream。 (大概你的PrintStream也需要是一个字段,因为你想在很多地方访问它。一旦完成,请确保你不小心给另一个变量同名。)