无法识别符号output.print()

问题描述:

我的代码无法识别打印出于某种原因。无法识别符号output.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,他们都说着同样的事情:
找不到符号 符号:方法打印(java.lang.String中)

+2

这不是真的清楚问题出在哪里是。请显示一个*简短*但完整的程序来演示这个问题。 – 2012-08-07 19:40:48

+0

错误信息是否包含行号?你能提供前几个错误的全文吗? – 2012-08-07 19:43:25

+0

我们可以回滚一些更改吗?当我们看到所有的田地是什么时,“in”的问题就很清楚了。 – 2012-08-07 19:51:38

那么,为什么你的理由通过解决问题是你在一个方法中声明它为局部变量,但试图在其他方法中访问它(在编辑中删除大量代码之前,你可以看到它)。如果你想在任何地方使用它,请将其作为一个领域。

至于与output的问题,如果你看第123行,output有一个字符串,而不是一个PrintStream。 (想必你的PrintStream需要也可以是现场的,因为你要访问它在许多地方,一旦这样做了,请确保你不小心给另一个变量相同的名称。)

+0

我修复了问题。谢谢!! – user1582825 2012-08-07 20:01:52