When I declared a variable like public int n the compiler is showing an error stating that it is the illegal start of an expression. Why is that. I am using JDK 1.8. Please help | Sololearn: Learn to code for FREE!
¡Nuevo curso! ¡Todo programador debería aprender IA Generativa!
Prueba una lección gratuita
0

When I declared a variable like public int n the compiler is showing an error stating that it is the illegal start of an expression. Why is that. I am using JDK 1.8. Please help

6th Aug 2016, 9:46 AM
Learner
Learner - avatar
3 Respuestas
0
I'm guessing youre putting the public int in a method? like the main method? If so, there's the problem. A method, including the main method, can only accept local variables. No public identifier. Can remove the public, or place it outside the main method/other methods.
6th Aug 2016, 10:14 AM
James
James - avatar
0
Thanks. It worked
6th Aug 2016, 12:03 PM
Learner
Learner - avatar
- 1
when you do public int make sure int is in ( )
6th Aug 2016, 10:06 AM
Aquarius
Aquarius - avatar