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 with input 2: 1: Lather and rinse. 2: Lather and rinse. Done. Hint: Declare and use a loop variable. import java.util.Scanner; public class ShampooMethod { /* Your solution goes here */ public static void main (String [] args) { Scanner scnr = new Scanner(System.in); int userCycles; userCycles = scnr.nextInt(); printShampooInstructions(userCycles); } }

Respuesta :

ijeggs

Answer:

import java.util.Scanner;

public class nu3 {

   public static void main(String[] args) {

       Scanner in = new Scanner(System.in);

       System.out.println("Enter number of cycles");

       int numCycles = in.nextInt();

       //Call the method

       printShampooInstructions(numCycles);

   }

   public static void printShampooInstructions(int numCycles){

                if (numCycles<1){

              System.out.println("Too few");

          }

          if (numCycles>4){

              System.out.println("Too Many");

          }

          else {

              for (int i = 1;i <= numCycles; i++) {

                  System.out.println( numCycles+ ": Lather and rinse");

                  numCycles--;

              }

              System.out.println("     Done");

          }

   }

}

Explanation:

This is solved using Java programming language

The method printShampooInstructions() is in bold in the answer section

I have also provided a complete program that request user to enter value for number of cycles, calls the method and passes that value to it

The logic here is using if .... else statements to handle the different possible values of Number of cycles.

In the Else Section a loop is used to decrementally print the number of cycles

ACCESS MORE