0

My first steps with Java. Is there an error in this code?

Hello community! This is my first post ever and I'm gonna ask, should someone have the time, a question regarding an extremely basic thing on Java. I can't figure it out. What's wrong with these lines? public class ej5{ public static void main(String[] args){ int nFinal=37; procBucle(nFinal); } public static void procBucle(int nFinal){ for(int i=0;i<nFinal;i++){ System.out.println(i); } return i; } } Thank you so much.

14th Oct 2018, 11:01 PM
Franco Antonio
Franco Antonio - avatar
3 Answers
0
remove this line... return i; You define your method with "void" which means it doesn't return anything.. Also, you attempt to return i, which is only a variable inside of your for loop, and your trying to use it outside of said loop
14th Oct 2018, 11:08 PM
LordHill
LordHill - avatar
+ 1
Thank you so much! That was my first exercise ever. Appreciated Rick
14th Oct 2018, 11:21 PM
Franco Antonio
Franco Antonio - avatar
0
No problem. keep it up!
14th Oct 2018, 11:24 PM
LordHill
LordHill - avatar