• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

Something wrong in my code?

 
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Saloon Keeper
Posts: 9538
79
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 9538
79
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 9538
79
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Note that

will never be true because of the order that you've placed your else-if's in.
 
I knew that guy would be trouble! Thanks tiny ad!
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic