2014-10-22 63 views
0

在以下代碼行中,出現一個錯誤,指出它無法在代碼中將inputString識別爲它的兩個實例中的符號。無法將inputString識別爲符號?

error: cannot find symbol 

inputString 

^ 

代碼:

import java.util.Scanner; 
import java.io.PrintStream; 
import java.lang.Math; 
import type.lib.*; 

public class Check06B 

{ 
    public static final String CODE_STRING = "||::::::||::||::|::|:|:|::||::|:::||::|:|:|::"; 
    public static final String CODE_NUMBERS = "0  1  2  3  4  5  6  7  8  9"; 
    public static final int CODE_LENGTH = 5; 
    public static final int ERROR_DIVISOR = 10; 

    public static void main(String[] args) 
    { 
     PrintStream print = new PrintStream(System.out); 
     Scanner input = new Scanner(System.in); 
     print.println("Enter a string of digits: "); 
     String x = input.nextLine(); 

     StringBuffer result = new StringBuffer("|"); 

     int sum = 0; 

     for (int i = 0; i < inputString.length(); i++) 
     { 
      String digit = inputString.substring(i, i + 1); 
      sum += Integer.parseInt(digit); 
      result.append(CODE_STRING.substring(CODE_NUMBERS.indexOf(digit),CODE_NUMBERS.indexOf(digit) + CODE_LENGTH)); 
     } 

     int crc= (ERROR_DIVISOR - (sum % ERROR_DIVISOR)) % ERROR_DIVISOR; 
     result.append(CODE_STRING.substring(CODE_NUMBERS.indexOf("" + crc),CODE_NUMBERS.indexOf("" + crc) + CODE_LENGTH)); 
     result.append("|"); 

     print.println("POSTNET Code: " + result.toString()); 
    } 
} 

回答

3

你從來沒有宣佈任何inputString變量。

也許你想用這個變量,而不是:

String x = input.nextLine(); 
1

愚蠢的錯誤 -

String x = input.nextLine(); 

應該

String inputString = input.nextLine();