I am trying to make a loop that prints "*" as a string a certain number of times, but I can't get it to work. Everything in the main method was given to me and must be used. Everything else I added and I don't know if I am on the right track or not. The end result is suppposed to print "*" seven times horizontally. Then each time it adds a "*", adds one to count, and compares to see if count is greater than or equal to the value I set. Then if it is true it ends the loop and if not it repeats the loop until true. I just don't know how express this in code.
public class LoopPractice
{
public String ast = "*";
public static void main(String[] args)
{
LoopPractice lp = new LoopPractice();
System.out.println(lp.getAstWhile(7));
}
public String getAstWhile()
{
int count = 0;
while (count <= 6)
{
System.out.print(count++);
}
return ast;
}
}
lp.getAstWhile(7)in theprintln()function, you're passing an argument butgetAstWhile()doesn't have any parameters.