Thursday, 14 May 2015

Pattern program 14


	import java.io.Console;
	class pattern14 {
		public static void main(String args[]) {
			int n;
			String s="";
			Console con=System.console();
			System.out.print("Enter your Number : ");
			n=Integer.parseInt(con.readLine());
			for(int i=1;i<=n;i++) {
				for(int j=n;j>i;j--) {
					System.out.print(" ");
				}
				for(int k=i;k>=1;k--) {
					System.out.print("*");
				}
				System.out.println();
			}
		}
	}

Wednesday, 13 May 2015

Pattern program 13


	import java.io.Console;
	class pattern13 {
		public static void main(String args[]) {
			for(int i = 1;i<=5;i++) {
				for(int j = 1;j<=i;j++)
					System.out.print(j);
				for(int j = 1;j<=9-2*i;j++)
					System.out.print(" ");
				for(int j = i;j>=1;j--) {
					if(j==5)
						continue;
					System.out.print(j);
				}
				System.out.println();
			}
		}
	}

Tuesday, 12 May 2015

Pattern program 12



public class pattern12{
    public static void main(String args[]) {
        int ln = 4;    //Number of lines/rows
        for(int i=1; i<=ln; i++){
            //Spacing Logic
            for(int s=i;s<=ln;s++){
                System.out.print("  ");
            }
            for(int j=1,p=i;j<=i;j++,p++){
                System.out.print(p+" ");
                if(j==i){
                    p--;
                    for(int k=1;k<i;k++,--p){
                        System.out.print(p+" ");
                    }
                }
            }
            System.out.println();
        }
    }
}

Monday, 11 May 2015

Pattern program 11


	import java.io.Console;
	class pattern11 {
		public static void main(String args[]) {
			int ln=9;   //Number of lines/rows
			for(int i=1;i<=ln;i++){
				if(i<=ln/2+1){
					for(int j=1;j<=i;j++)
						System.out.print("*");
				} else {
					for(int j=ln-i+1;j>0;j--)
						System.out.print("*");
				}
				System.out.println();
			}
		}
	}

Sunday, 10 May 2015

Pattern program 10



public class pattern10 {
    public static void main ( String arg[] ){
        int ln = 5 , p=1;
        for(int i=0;i<ln;i++){
            for(int s=ln-1;s>i;s--){
                System.out.print(" ");
            }
            for(int j=0;j<=i*2;j++){
                System.out.print(p);
                p = (p==1)?0:1;
            }
            System.out.println();
        }
    }
}

Saturday, 9 May 2015

Pattern program 9



	public class pattern9 {
		public static void main( String arg[]){
			int ck=0,c=2;
			while(c>0){
				if(ck==0){
					for(int i=1,r=5;i<=5;i++,r--){
						for(int j=1;j<=r;j++){
							System.out.print(j);
						}
						System.out.println();
					}
					ck++;
				} else{
				for(int i=2;i<=5;i++){
					for(int j=1;j<=i;j++){
						System.out.print(j);
					}
					System.out.println();
				}
			c--;
			}
		}
	}

Send by Yawer Moin

	import java.io.*;
	class pattern9 {
		public static void main(String args[]) {
			Console con=System.console();
			int n;
			n=Integer.parseInt(con.readLine());
			for(int i=1,r=n;i<=n;i++,r--) {
				for(int j=1;j<=r;j++)
					System.out.print(j);
				System.out.println();
				if(i==n) {
					for(int j=2;j<=n;j++) {
						for(int k=1;k<=j;k++) {
							System.out.print(k);
						}
						System.out.println();
					}
				}
			}
		}
	}

Friday, 8 May 2015

Pattern program 8


	public class pattern8 {
		public static void main( String arg[]){
			int ck=0,c=2;
			while(c>0){
				if(ck==0){
					for(int i=1;i<=5;i++){
						for(int j=1;j<=i;j++){
							System.out.print(j);
						}
						System.out.println();
					}
					ck++;
				} else{
					for(int i=1,r=5-1;i<=5-1;i++,r--){
						for(int j=1;j<=r;j++){
							System.out.print(j);
						}
						System.out.println();
					}
				}
				c--;
			}
		}
	}

Thursday, 7 May 2015

Pattern program 7



	public class pattern7 {
		public static void main( String arg[]){
			for(int i=1,r=5;i<=5;i++,r--)
			{
				for(int j=1;j<=r;j++)
				{
					System.out.print(j);
				}
				System.out.println();
			}
		}
	}

Wednesday, 6 May 2015

Pattern program 6


	public class pattern6 {
		public static void main( String arg[]){
			for(int i=1;i<=5;i++)
			{
				for(int j=5;j>=i;j--)
				{
					System.out.print(j);
				}
				System.out.println();
			}
		}
	}

Tuesday, 5 May 2015

Pattern program 5


	public class pattern5 {
		public static void main( String arg[]){
			for(int i=1;i<=5;i++)
			{
				for(int j=1;j<=i;j++)
				{
					System.out.print(j);
				}
				System.out.println();
			}
		}
	}

Monday, 4 May 2015

Pattern program 4




	import java.io.*;
	class pattern4
	{
		public static void main(String args[])
		{
			Console con = System.console();
			int n = Integer.parseInt(con.readLine());
			for(int i=1;i<=n;i++)
			{
				for(int j=1;j<=i;j++)
					System.out.print(j+" ");
				System.out.println();
			}
		}
	}

Sunday, 3 May 2015

Pattern program 3

Input 1 output *
Input 2 output
**
**

Input 3 output
***
* *
***

Input 4 output
****
* *
* *
****

	import java.io.*;
	class pattern3
	{
		public static void main(String args[])
		{
			Console con = System.console();
			int n = Integer.parseInt(con.readLine());
			for(int i=1;i<=n;i++)
			{
				if(i==1||i==n)
				{
					for(int j=1;j<=n;j++)
						System.out.print(" *");
				}
				else
				{
					for(int j=1;j<=n;j++)
					{
						if(j==1||j==n)
							System.out.print(" *");
						else
							System.out.print("  ");
					}
				}
				System.out.println();
			}
		}
	}

Saturday, 2 May 2015

Pattern program 2


Input 1 output *
Input 2 output
 *
**

Input 3 output
  *
 * *
* * *

Input 4 output
   *
  *  *
 *    *
* * * *

	import java.io.*;
	class pattern2
	{
		public static void main(String args[])
		{
			Console con = System.console();
			int n = Integer.parseInt(con.readLine());
			for(int i=1;i<=n;i++)
			{
				if(i==n)
				{
					for(int j=1;j<=n+i-1;j++)
						System.out.print(" *");
					}
				else
				{
					for(int j=1;j<=n-i;j++)
						System.out.print("  ");
					for(int j=n-i+1;j<=n+i-1;j++)
					{
						if(j==n-i+1||j==n+i-1)
							System.out.print(" *");
						else
							System.out.print("  ");
					}
					System.out.println();
				}
			}
		}
	}

Optimize solution of pattern program 2



import java.io.Console;
class Loop3
{
 public static void main(String args[])
 {
  int n;
  String s="";
  Console con=System.console();
  System.out.print("Enter your Number : ");
  n=Integer.parseInt(con.readLine());

  for(int i=1;i<=n;i++)
  {
   for(int j=1;j<=n;j++)
   {
    if(i<=n-j)
    {
     System.out.print(" ");
    }

   }
   if(i>=1)
   {
    s+="*";
    System.out.print(s); 
   }
   System.out.println();
  }
 }
}

Friday, 1 May 2015

Optimize solution of pattern program 1



	import java.io.*
	public class loop {
		public static void main(String args[]) {
			String ss = "";
			Console con = System.console();
			int num = Integer.parseInt(con.readLine());
			for(int i = 0;i<num;i ++) {
				ss+="* ";
				System.out.println(ss);
			}
		}
	}

Pattern program 1


	import java.io.*;
	class pattern1
	{
		public static void main(String args[])
		{
			Console con = System.console();
			System.out.print("Enter Array length");
			int n = Integer.parseInt(con.readLine());
			int a[] = new  int[n];
			int max=0;
			System.out.print("Enter Array value");
			for(int i=0;i<a.length;i++)
			{
				a[i] = Integer.parseInt(con.readLine());
			}
			for(int i=0;i<a.length;i++)
			{
				if(a[i]>max)
					max=a[i];
			}
			for(int i=max;i>=1;i--)
			{
				for(int j=1;j<a.length;j++)
				{
					if(a[j]>=i)
						System.out.print("*");
					else
						System.out.print("-");
				}
				System.out.println();
			}
		}
	}