• Post Reply Bookmark Topic Watch Topic
  • New Topic

What's wrong with my for loop?  RSS feed

 
Bob Jinkins
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying to make a for loop that displays the prime numbers below the number the user enters but it's not working for some reason. I think I'm close but the output never prints out any numbers.
 
Liutauras Vilda
Sheriff
Posts: 4928
334
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please fix code indentation first, then give a try again, then see what happens.
Never ever do not omit curly braces. Never, even if the body of the loop it is 1 line. Or body of if statement.
 
Les Morgan
Rancher
Posts: 779
19
C++ Java MySQL Database Netbeans IDE Oracle Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well to start off with you are not using the curly braces to define your contexts, so all of your "for" statements only take the next line and then stop... they look like this:

Since you are using a Scanner on System.in, execution waits until you hit enter to process your input.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!