Answer:
The following are the program in the Java Programming Language.
//define a function
public void dashedLine (int x)
{
//check the variable 'a' is greater than 0
if (x>0)
{
//declare integer data type variable
int i;
//set the for loop that iterates from 1 to variable 'a'
for (i=1;i<=x;i=i+1)
{
//print the following dashes
System.out.print("-");
}
//for empty space
System.out.println("");
}
}
Step-by-step explanation:
The following are the description of the program.
- Define a function 'dashedLine()' and pass an argument 'x' in the function's parameter.
- Then, set the if conditional statement that check the argument x is greater than 0 or not.
- Then, declare the variable 'i' and set the for loop statement that iterates from 1 to the variable x then, print the dashes and print the empty spaces after every loop statement.