Variable might not have been initialized error

前端 未结 11 1577
孤城傲影
孤城傲影 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 06:08

    You declared them but did not provide them with an intial value - thus, they're unintialized. Try something like:

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

    and the warnings should go away.

提交回复
热议问题