Sunday, July 22, 2012

Pattern Program Using BlueJ

This is a pattern displaying program. The pattern is


1 2 3 4 5 6

1 3 5 7 9 11

1 4 7 10 13 16

1 5 9 13 17 21



class Pat
{
int i,j,x;
public void take()
{
for(i=1;i<=4;i++)
{
x=1;
for(j=1;j<=6;j++)
{
System.out.print(" "+x);
x=x+i;
}
System.out.println();
}
}
public static void main(String args[])
{
Pat ob=new Pat();
ob.take();
}
}

Here is another pattern program which depends on user interaction:

if user input 1 -> {}
if user input 2 ->
{}{}
{}{}

if user input 3 ->
{}{}{}
{}{}{}
{}{}{}



import java.io.*;
class Pat1
{
int i,j,n;

BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
public void take() throws Exception
{
System.out.println("Enter '1', '2' or '3':");
n=Integer.parseInt(br.readLine());
for(i=0;i< n;i++)
{
for(j=0;j< n;j++)
{
System.out.print("{}");
}
System.out.println();
}
}
public static void main(String args[]) throws Exception

{
Pat1 ob=new Pat1();
ob.take();
}
}



Related PostBlueJ Programs On Pattern

2 comments:

  1. sir plz post some java programs on stack & queue
    principle with their variable description &algorithm
    plzzzzz help sir its urgent

    ReplyDelete
    Replies
    1. I will post the program very soon, please visit the site after 2-3 days.

      Delete

Subscribe via email

Enter your email address:

Delivered by FeedBurner