Java help CHALLENGE8.1.2: Method with loop: Shampoo Write a method printShampool
ID: 3590524 • Letter: J
Question
Java help
CHALLENGE8.1.2: Method with loop: Shampoo Write a method printShampoolnstructions0, 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. 1 import java.util.Scanner; 1 test 3 public class ShampooMethod f 4 passed 6 7 public static void main (String [ args) All tests passed printShampooInstructions (2); 10 return 12 RunExplanation / Answer
Below is your code
public class ShampooMethod {
public static void printShampooInstructions(int numCycles) {
if (numCycles < 1) {
System.out.println("Too few.");
}
else if (numCycles > 4) {
System.out.println("Too many.");
}
else {
int N = 1;
while (N <= numCycles) {
System.out.println(N + ": Lather and rinse.");
++N;
}
System.out.println("Done.");
}
}
public static void main(String[] args) {
printShampooInstructions(2);
return;
}
}
Output
1: Lather and rinse.
2: Lather and rinse.
Done.
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.