Write the definition of a function dashedLine, with one parameter, an int. If the parameter is negative or zero, the function does nothing. Otherwise it prints a complete line terminated by a new line character to standard output consisting of dashes (hyphens) with the parameter's value determining the number of dashes. The function returns nothing.

Respuesta :

ijeggs

Answer:

public static void dashedLinses(int num){

       if(num>0){

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

               System.out.print("-");

           }

           System.out.println();

       }

   }

}

Explanation:

  • The function is written with Java programming language
  • As required by the question, it accepts an int parameter and returns nothing.
  • An if statement is used to check the condition of n greater than 0
  • Using a for loop, it outputs a line whose length is determined by the value of the parameter
  • A complete code with the main method is given below

public class num9 {

   public static void main(String[] args) {

   int num= 2;

   dashedLinses(num);

   }

   public static void dashedLinses(int num){

       if(num>0){

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

               System.out.print("-");

           }

           System.out.println();

       }

   }

}