0

Why is the error occurring? I've already initialized the variable.

https://code.sololearn.com/c0T4q46QNjTs/?ref=app

24th Sep 2017, 9:13 AM
Diwakar
Diwakar - avatar
4 Réponses
+ 12
No, its never initialized! You have to assign a value to your variables first, try this : int a = 0, b = 0, c = 0, count; OR -- A variable gets itself initialized only if its declared static. Like if you make your int as static int then the initialized value would be 0.
24th Sep 2017, 9:21 AM
Dev
Dev - avatar
+ 9
@Diwakar : Adding static keyword makes it a class variable, hence you have to declare it before the main() method. static int a, b, c, count; public static void main(String[] args) { //... } You're welcome <3
27th Sep 2017, 7:29 AM
Dev
Dev - avatar
+ 1
Thanks! It's working If i initialize them to 0. But when i use static, it is showing illegal start of expression.
27th Sep 2017, 7:26 AM
Diwakar
Diwakar - avatar
+ 1
Thanks! It worked.
27th Sep 2017, 7:34 AM
Diwakar
Diwakar - avatar