return - Newbie Java Programmer needs help involving for loops -
i trying create example program me remember how operate loops, when ran through compiler
. compiler said missing return statement
. add it? here code:
public class loopexample { public string bam() { (int = 0; < 8; i++) { system.out.println(i); } } }
edit received answer, main says 'cannot find symbol'... here code main:
public class loopexampletestdrive { public static void main(string[] args) { bam looper = new bam(); system.out.println(looper); } }
i advise try understand how object oriented languages work first.
that being said, main reason why code doesn't work, because try make object of class bam new bam()
. class unfortunately doesn't exist method in class. solution like:
public class loopexample { public void bam() { (int = 0; < 8; i++) { system.out.println(i); } } public static void main(string[] args) { new loopexample().bam(); } }
as said: try understand object oriented programming first, before trying continue programming in java. essential able write working code.
ps: complete, best way write want do, follows.
public class loopexample { public static void main(string[] args) { for(int = 0; < 8; i++) { system.out.println(i); } } }
Comments
Post a Comment