在以下代码行中,出现错误,表示无法将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());
}
}
答案 0 :(得分:3)
您永远不会声明任何inputString
变量。
也许你打算改用这个变量:
String x = input.nextLine();
答案 1 :(得分:1)
愚蠢的错误 -
String x = input.nextLine();
应该是
String inputString = input.nextLine();