Search This Blog

Loading...

Thursday, August 21, 2014

Java Program to print the pattern 1,11,111,1111,....n


In this program we will print the pattern 1,11,111,1111,....n

import java.io.*;

class P
{
 int i,j,n;
 BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
 void show() throws Exception
 {
      System.out.println("\nEnter the value of 'n':");
      n=Integer.parseInt(br.readLine());
      for(i=0;i      {
           for(j=0;j<=i;j++)
           {
                System.out.print("1");
            }
            if(i!=n-1)
            System.out.print(",");
        }
    }
    public static void main(String args[])throws Exception
    {
      P ob=new P();
         ob.show();
        }
    }

Thursday, August 7, 2014

BlueJ Pattern Program


In this program we will display the following pattern:

1
2 2
3 3 3
4 4 4 4
n n n n n
4 4 4 4
3 3 3
2 2
1

public class A
{
int i,j,x,y;
public void show()
{
x=1;
y=1;

 for(i=1;i<=9;i++)
 {
 
  for(j=1;j<=x;j++)
      {
          if(i==5)
          System.out.print("n");
          else
          System.out.print(y);
        }
        if(i<=9/2)
        {
            y++;
        x++;
    }
        else
        {
            y--;
        x--;
    }
     System.out.println();
     }
}
public static void main(String args[])
{
 A ob=new A();
 ob.show();
}
}

CHECK HERE FOR PREVIOUS POSTS

Google+ Followers

Subscribe via email

Enter your email address:

Delivered by FeedBurner