I am required to use nested for loops and print(\'*\', end=\' \')
to create the pattern shown here:
And here is my code. I have figured out the first t
Pattern 1
for x in range(1,11):
print("*"*x)
Output
*
**
***
****
*****
******
*******
********
*********
**********
Pattern 2
for x in range(10,0,-1):
print("*"*x)
Output
**********
*********
********
*******
******
*****
****
***
**
*
Pattern 3
i=0
for x in range(10,0,-1):
print(" "*i,end="")
print("*"*x)
i+=1
Output
**********
*********
********
*******
******
*****
****
***
**
*
Pattern 4
i=10
for x in range(1,11):
print(" "*i,end="")
print("*"*x)
i-=1
Output
*
**
***
****
*****
******
*******
********
*********
**********
for i in range(1,7): print(" "(7-i)+""*(i))
Output :
*
**
***
Try this one!
a)
*
**
***
****
*****
public class Main {
public static void main(String[] args) {
int n=5;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=i;j++)
{
System.out.print("*");
}
System.out.println();
}
}
}
b)
*****
****
***
**
*
public class Main {
public static void main(String[] args) {
int n=5;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=(i-1);j++)
{
System.out.print(" ");
}
for(int j=i;j<=n;j++)
{
System.out.print("*");
}
System.out.println();
}
}
}
c)
*
**
***
****
*****
public class Main
{
public static void main(String[] args)
{ int n=5;
for(int i=n;i>0;i--)
{
for(int j=1;j<=(i-1);j++)
{
System.out.print(" ");
}
for(int j=i;j<=n;j++)
{
System.out.print("*");
}
System.out.println();
}
}
}
d)
*****
****
***
**
*
public class Main
{
public static void main(String[] args) {
int n=5;
for(int i=n;i>0;i--)
{
for(int j=1;j<=i;j++)
{
System.out.print("*");
}
System.out.println();
}
}
}
var n = 5;
for(int row = 0 ; row < n; row++)
{
for(int col = 1; col <= n; col++)
{
if(col < n - row)
{
Console.Write(" ");
}
else
{
Console.Write("*");
}
}
Console.WriteLine();
}
(D)
for i in range(0,5):
for j in range(0,i+1):
print("*",end="")
print()
for k in range(5,0,-1):
for l in range(k-1,0,-1):
print("*",end="")
print()
for i in range(1,n+1): print '{:>{}}'.format('#'*i, n)
this is For pattern D
for i in range(1,n-1): print '{:>{}}'.format('#'*i, n)
this is For pattern c