Monday, September 15, 2014

Printing Any Word In Pattern Format Using BlueJ


Suppose user entered any 'happy' and the following pattern will be displayed.


happyyppah
happ ppah
hap pah
ha ah
h h
ha ah
hap pah
happ ppah
happyyppah

Also Read: Computer Teacher in Burdwan

import java.io.*;
class WordPattern
{
 String str;
 int i,j,k,x=0,len;
 BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
 void show() throws Exception
 {
         System.out.println("\nEnter the string:");
         str=br.readLine();
         len=str.length();
         for(i=0;i< len*2-1;i++)
         {
              for(j=0;j< len-x;j++)
              System.out.print(str.charAt(j));
              if(i!=0 && i!=len*2-2)
              System.out.print(" ");
               for(j=len-1-x;j >=0;j--)
              System.out.print(str.charAt(j));
             System.out.println();
            if(i<=len/2+1)
            x++;
            else
            x--;
            }
        }
       
    public static void main(String args[])throws Exception
    {
        WordPattern ob=new WordPattern();
         ob.show();
        }
    }

Related PostBlueJ Programs On Pattern

No comments:

Post a Comment

Subscribe via email

Enter your email address:

Delivered by FeedBurner