PYRAMID SHAPE: USING FUNCTION CALLING ANOTHER FUNCTION
AIM: TO PRINT THE PYRAMIDAL SHAPE USING LOOP CONCEPT AND PRINTING NUMBERS
EXAMPLE:
1
2 3
4 5 6
7 8 9 10
SYNTAX
import java.io.*;
class pattern2
{
public static void main(String args[])throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter No. of lines to print");
int n= Integer.parseInt(br.readLine());
int x=1;
int l=n-1;
for(int i=1;i<=n;i++)
{ spaces(l--);
for(int j=1;j<=i;j++)
{System.out.print(x+" ");
x++;
}
System.out.println();
}
}
public static void spaces(int x)
{
for(int i=1;i<=x;i++)
{
System.out.print(" ");
}
}
}
Comments
Post a Comment