Thursday, February 26, 2015

BlueJ Program Of Printing Word In A Specific Pattern



In this BlueJ program user will enter any word and the word will be displayed
following a pattern. If the entered word is 'ORDER', the output would be:

D
R D E
O R D E R

import java.io.*;
class Word
{
 String s1;
 int i,j,len,x=0,mid;
 BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
 public void takeWord() throws Exception
 {
  System.out.println("Enter the word:");
  s1=br.readLine();
  len=s1.length();
  for(i=0;i<=len/2;i++)
  {
  mid=len/2-i;
  for(j=mid;j<=mid+x;j++)
  {
   System.out.print(s1.charAt(j));
   }
   x=x+2;
   System.out.println();
   }
  }
   public static void main(String args[])throws Exception
  {
Word ob=new Word();
   ob.takeWord();
   }

No comments:

Post a Comment

Subscribe via email

Enter your email address:

Delivered by FeedBurner