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--;
}
}
{
WordPattern ob=new WordPattern();
ob.show();
}
}
Related Post: BlueJ Programs On Pattern
No comments:
Post a Comment