• Post Reply Bookmark Topic Watch Topic
  • New Topic

Something wrong in my code?  RSS feed

 
John Sing
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi I have to make a variation of the famous "FizzBuzz" code where I have the user input the number they want to go up to and it can only print 11 numbers per line. My code can do all that just it repeats the same number 11 times instead of moving onto the next number and I am not sure why. Can someone help me fix it?



Here is the output I get from entering 50 into that code.
"
Loza Loza Loza Loza Loza Loza Loza Loza Loza Loza Loza
Coza Coza Coza Coza Coza Coza Coza Coza Coza Coza Coza


Coza Coza Coza Coza Coza Coza Coza Coza Coza Coza Coza
Loza Loza Loza Loza Loza Loza Loza Loza Loza Loza Loza

Coza Coza Coza Coza Coza Coza Coza Coza Coza Coza Coza


CozaLoza CozaLoza CozaLoza CozaLoza CozaLoza CozaLoza CozaLoza CozaLoza CozaLoza CozaLoza CozaLoza


Coza Coza Coza Coza Coza Coza Coza Coza Coza Coza Coza
Woza 49 Woza 49 Woza 49 Woza 49 Woza 49 Woza 49 Woza 49 Woza 49 Woza 49 Woza 49 Woza 49
Loza Loza Loza Loza Loza Loza Loza Loza Loza Loza Loza"

Any help would be appreciated. Thanks
 
Carey Brown
Saloon Keeper
Posts: 3329
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First of all, clean up your indentation.


I'm not quite sure why you have nested loops.
is unnecessary, the for() loop already guarantees this.
 
Carey Brown
Saloon Keeper
Posts: 3329
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your brackets here are unnecessary

Seems like your inner loop for only printing 11 per line is not the right tool for the job. Just create an int variable 'count' and before each print, increment it and test it to see if it's greater than 11. If so then do a System.out.println().
 
Carey Brown
Saloon Keeper
Posts: 3329
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Note that

will never be true because of the order that you've placed your else-if's in.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!