Thursday, November 19, 2015

BlueJ Program On Printing A Word In A Specific Pattern


Printing any word in the following pattern:

child
hildc
ildch
ldchi
dchil
child


import java.io.*;
class Pat
{
int i,j,len;
String str;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
 public void take () throws Exception
 {
    System.out.print("\nTake the string:");
    str=br.readLine();
    len=str.length();
    for( i=0;i< len;i++)
    {
    for(j=0;j< len;j++)
    {
     System.out.print(str.charAt(j));
     }
     str=str.substring(1)+str.charAt(0);
     System.out.println();
     }
     System.out.println(str);
     }
   public static void main(String args[]) throws Exception
   {
    Pat object=new Pat();
    object.take();
    }
    }

Related Post: BlueJ Programs on String/Sentence

No comments:

Post a Comment

Subscribe via email

Enter your email address:

Delivered by FeedBurner