对拒绝合作的Java代码进行故障诊断

Azu*_*ame 4 java string

名为"code"的字符串似乎无法读取.为什么这样,我该如何解决?

我的代码(导致问题的代码段):

String code;
for(int z = 0; z<x;z= z+0) // Repeat once for every character in the input string remaining
{
    for(int y=0;y<2;y++) //Repeat twice
    {
        c = (char)(r.nextInt(26) + 'a'); //Generate a random character (lowercase)
        ca = Character.toString(c);
        temp = code;
        code = temp + ca; //Add a random character to the encoded string
    }
Run Code Online (Sandbox Code Playgroud)

我的错误报告:

--------------------Configuration: <Default>--------------------
H:\Java\Compiler.java:66: variable code might not have been initialized
        temp = code;
               ^
1 error

Process completed.
Run Code Online (Sandbox Code Playgroud)

(我使用的是JCreator 5.00,Java 7.)

(是的,错误报告看起来很愚蠢,但Stack Overflow会将其读作编码.)

Kir*_*oll 8

code如果x为零,会有什么价值?答案是它根本没有价值(甚至没有null).如果您愿意,可以将其初始化为空字符串:

String code = "";
Run Code Online (Sandbox Code Playgroud)