• Post Reply Bookmark Topic Watch Topic
  • New Topic

New Code  RSS feed

 
Brook Esper
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can someone tell me how to get all the names printed? My program prints only one name, but I want all the names to be printed.

Course class


TestCourse
 
Knute Snortum
Sheriff
Posts: 4279
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Take a look at you for loop in TestCourse.
 
Brook Esper
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Knute Snortum wrote:Take a look at you for loop in TestCourse.


Ok and?
 
Knute Snortum
Sheriff
Posts: 4279
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have the printlns indented under the for loop, but are they really controlled by the loop?
 
Brook Esper
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Knute Snortum wrote:You have the printlns indented under the for loop, but are they really controlled by the loop?


How can I fix it?
 
Ganish Patil
Ranch Hand
Posts: 529
19
Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Netbeans IDE Spring Tomcat Server
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
for (int i = 0; i < course1.getNumberOfStudents(); i++);
remove this semicolon, here loop doesn't reach to below code. scope of int i is limited to loop circular bracket so can't access here so declare int i before the loop.
 
Knute Snortum
Sheriff
Posts: 4279
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look at this tutorial then if you can't figure it out, look below:

Remove the semicolon at the end of the for() line and put braces {} around the lines controlled by the for loop.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!