Search This Blog

Thursday, 21 July 2016

Write an interactive program to print a string entrered in a pyramid form.

import java.util.Scanner;

class  Pyramid
{

    public static void main(String[] args)
{
 
        int c=0,v=0;
        String s;
        Scanner in =new Scanner(System.in);
        System.out.println("Enter String :");
        s = in.nextLine();
     
        for(int i = 0 ;i<s.length();i++)
        {
            for(int j=s.length()/2 + 1;j>=i;j--)
System.out.print(" ");
for(int k=0;k<=i;k++)
{
char ch = s.charAt(k);
System.out.print(ch+" ");
}
System.out.println();
        }
    }
}

output:
Enter String:
SCET
        S
     S   C
  S    C    E
S   C   E   T

No comments:

Post a Comment