Variable might not have been initialized error

前端 未结 11 1604
孤城傲影
孤城傲影 2020-11-21 05:50

When i try to compile this:

public static Rand searchCount (int[] x) 
{
    int a ; 
    int b ; 

    ...   

    for (int l= 0; l

        
11条回答
  •  北恋
    北恋 (楼主)
    2020-11-21 05:57

    You haven't initialised a and b, only declared them. There is a subtle difference.

    int a = 0;
    int b = 0;
    

    At least this is for C++, I presume Java is the same concept.

提交回复
热议问题