• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Bear Bibeault
  • Liutauras Vilda
  • Devaka Cooray
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • Henry Wong
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • salvin francis
  • Frits Walraven
  • Piet Souris

method with loop

 
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
so I have to write a code for this question:
Write a method printShampooInstructions(), with int parameter numCycles, and void return type. If numCycles is less than 1, print "Too few.". If more than 4, print "Too many.". Else, print "N: Lather and rinse." numCycles times, where N is the cycle number, followed by "Done.". End with a newline. Example output for numCycles = 2:
1: Lather and rinse.
2: Lather and rinse.
Done.

Hint: Declare and use a loop variable.


but what I've gotten so far is giving me errors and im not sure what im doing wrong. Can someone help me fix my code?
 
Sheriff
Posts: 14990
250
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check the names you're using. Java is very exact so if you're missing just one letter, you'll get errors.
 
Junilu Lacar
Sheriff
Posts: 14990
250
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The error messages should give you a clue as to which name you got wrong.
 
Hanna Roberts
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
oh ok thanks I'll check
 
Ranch Hand
Posts: 116
11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you allowed to use an IDE (Integrated Development Environment) or are you coding in something like Notepad?
An IDE like IntelliJ will catch typo errors like this for you.
 
Hanna Roberts
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I usually use eclipse IDE but this one was out of thee book so I didn't write it in there. Anyways I fix it, thanks for thee help that's all it was lol.
 
Marshal
Posts: 67939
258
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would makr you down for writing your loop like that. Remember the default format for a for loop is there for a good reason: it works.The + will work as expected because all +s are to the left of the String literal. You can move the ++ into the loop like this:-
 
Won't you be my neighbor? - Fred Rogers. tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!