for these guidelines:
Write the definition of a method dashedLine , with one parameter, an int .
If the parameter is negative or zero, the method does nothing. Otherwise it prints a complete line terminated by a newline to standard output consisting of dashes (hyphens) with the parameter’s value determining the number of dashes. The method returns nothing.
I wrote the following code, but it only prints one hyphen when I run in eclipse and give it a test parameter of 5. I’m thinking I may need to use a for loop instead. I think it loops within the loop therefor only giving one hyphen back.
how can I ‘remedy’ this code?
void dashedLine(int x)
{
int i=0;
if(x>0)
{
if(i<=x)
{
i++;
System.out.print("-");
}
else
System.out.print("\n");
}
}
But there is no loop.
ifis not a loop.forwhileanddo whileare the three different loops in Java. You should rather have: