Monday, June 16, 2014

Printing Pattern Using Java Language


Write a program to print the following pattern

J
EE
UUU
LLLLL
BBBBB 



class PatternPrint

{
 String s="BLUEJ";
int i,j,len;
void show()
{
 len=s.length();
for(i=len-1;i>=0;i--)
{
 for(j=len-1;j>=i;j--)
{
 System.out.print(s.charAt(i));
}
System.out.println();
}
}
public static void main(String args[])
{
 PatternPrint ob=new PatternPrint();
ob.show();
}
}


The above program is not dynamic. This program can be made dynamic, means the letters of the pattern may be as per user choice.


import java.io.*;

class PatternPrint
{
 String s";
int i,j,len;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

void show() throws Exception

{
System.out.println("Enter the word:");
s=br.readLine();
 len=s.length();
for(i=len-1;i>=0;i--)
{
 for(j=len-1;j>=i;j--)
{
 System.out.print(s.charAt(i));
}
System.out.println();
}
}
public static void main(String args[])throws Exception
{
 PatternPrint ob=new PatternPrint();
ob.show();
}
}

1 comment:

Subscribe via email

Enter your email address:

Delivered by FeedBurner