Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Variable Initialisation error.

$
0
0
  int num;
        String numx;   // compiler states that numx isn't initialised.
        for (int count=0;count<4;count++){
        num = (int)(Math.random()*9);
        numx += num+" ";
        }


I realised I have to insert a arbitrary String numx=""; for it to work.

Why is this so ?

I know that a local variable must be declared before it can be used, but does it need to be initialised before use as well ?

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>