JAva Write the definition of a method named printPowerOfTwoS
JAva
Write the definition of a method named printPowerOfTwoStars that receives a non-negative integer n and prints a string consisting of \"2 to the n\" asterisks. So, if the method received 4 it would print 2 to the 4 asterisks, that is, 16 asterisks:
****************
and if it received 0 it would print 2 to the 0 (i.e. 1) asterisks:
*
The method must not use a loop of any kind (for, while, do-while) to accomplish its job.
Solution
public void printPowerOfTwoStars(int n)
{
if(n>=0)
{
int length=Math.pow(2,n);
int count=0;
abc:
System.out.print(\"*\");
count=count+1;
if(count<length)goto abc;
}
else
{
System.out.println(\"invalid power value input \");
}
}
