import java.io.BufferedReader;
import java.io.InputStreamReader;
public class Main
{
public static void main(String args[])
{
int n = 0;
try
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.print("\nEnter the number of rows : ");
n = Integer.parseInt(br.readLine());
for(int i = 0; i < n; i++)
{
for(int j= 0; j < (n-i); j++)
{
System.out.print(" ");
}
for(int j = 0; j <= i; j++)
{
System.out.print("* ");
}
System.out.print("\n");
}//for i
for(int i = 0; i < n; i++)
{
for(int j = 0; j <= i; j++)
{
System.out.print(" ");
}
for(int j= 0; j < (n-i); j++)
{
System.out.print("* ");
}
System.out.print("\n");
}//for i
}
catch(Exception e)
{
}
}
}
Output :-
*
* *
* * *
* * * *
* * * * *
* * * * *
* * * *
* * *
* *
*
import java.io.InputStreamReader;
public class Main
{
public static void main(String args[])
{
int n = 0;
try
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.print("\nEnter the number of rows : ");
n = Integer.parseInt(br.readLine());
for(int i = 0; i < n; i++)
{
for(int j= 0; j < (n-i); j++)
{
System.out.print(" ");
}
for(int j = 0; j <= i; j++)
{
System.out.print("* ");
}
System.out.print("\n");
}//for i
for(int i = 0; i < n; i++)
{
for(int j = 0; j <= i; j++)
{
System.out.print(" ");
}
for(int j= 0; j < (n-i); j++)
{
System.out.print("* ");
}
System.out.print("\n");
}//for i
}
catch(Exception e)
{
}
}
}
Output :-
*
* *
* * *
* * * *
* * * * *
* * * * *
* * * *
* * *
* *
*
No comments:
Post a Comment