prowessapps.in Pattern Programs

*
* *
* * *
* * * *
* * * * * 
SOLUTION :
class Test {
 public static void main(String[] a)
 {
  for(int i = 1; i<=5; i++) {
   for(int j = 1; j<=i; j++) {
    System.out.print("*");
   }
   System.out.println();
  }
 }
}
          *
        *   *
      *   *   *
    *   *   *   *
  *   *   *   *   *
SOLUTION :
class Test {
 public static void main(String[] a)
 {
  for(int i = 1; i<=5; i++) {
   for(int j = 5; j>=i; j--) {
    System.out.print(" ");
   }
   for(int k = 1; k<=i; k++) {
    System.out.print("* ");
   }
   System.out.println();
  }
 }
}
A
A B
A B C
A B C D
A B C D E
SOLUTION :
class Test {
 public static void main(String[] a)
 {
  for(char i = 'A'; i<='E'; i++) {
   for(char j = 'A'; j<=i; j++) {
    System.out.print(j+" ");
   }
   System.out.println();
  }
 }
}
        1
      121
    12321
 1234321
SOLUTION :
class Test {
 public static void main(String[] a)
 {
  for(int i = 1; i<=4; i++) {
   for(int j = 3; j>=i; j--) {
    System.out.print(" ");
   }
   for(int k = 1; k<=i; k++) {
    System.out.print(k);
   }
   for(int m = i-1; m>=1;m--) {
    System.out.print(m);
   }
   System.out.println();
  }
 }
}
1
21
123
4321
12345
SOLUTION :
class Test {
 public static void main(String[] a)
 {
  for(int i = 1; i<=5; i++) {
   if(i%2==0){
    for(int j = 1; j<=i; j++) {
     System.out.print(j);
    }
   }
   else {
    for(int j = i; j>=1; j--) {
     System.out.print(j);
    }
   }
   System.out.println();
  }
 }
}
1234321
   12321
     121
       1
SOLUTION :
class Test {
 public static void main(String[] a)
 {
  for(int i =1; i<=4; i++) {
   for(int j =1; j < i;j++) {
    System.out.print(" ");
   }
   for(int j = 1; j<=5-i; j++) {
    System.out.print(j);
   }
   for(int k = 4-i;k>=1; k--) {
    System.out.print(k);
   }
   System.out.println();
  }
 }
}


       *
    * * *
 * * * * *
    * * *
       *
SOLUTION :
import java.util.Scanner;
class Test { 
 public static void main(String[] a)
 {
  Scanner s=new Scanner(System.in);
  System.out.print("Enter a Num: ");
  int n = s.nextInt();
  for(int i = 1; i<=n; i++) {
   for(int j = 0; j< n-i; j++) {
    System.out.print(" ");
   }
   for(int k=0; k< (2*i)-1; k++) {
    System.out.print("*");
   }
   System.out.println();
  }
  for(int i = 1; i< n;i++) {
   for(int j = 0; j< i; j++) {
    System.out.print(" ");
   }
   for(int k=0; k< 2*(n-i)-1; k++){
    System.out.print("*");
   }
   System.out.println();
  }
 }
}
0
1 0
0 1 0
1 0 1 0 
0 1 0 1 0
SOLUTION :
class Test {
 public static void main(String[] a)
 {
  for(int i = 0; i<=4; i++) {
   for(int j = 0; j<=i; j++) {
    System.out.print((i+j)%2+" ");
   }
   System.out.println();
  }
 }
}
2
4 6
8 10 12
SOLUTION :
class Test {
 public static void main(String[] a)
 {
  int k = 1;
  for(int i = 1; i< 4; i++) {
   for(int j = 1; j<=i; j++) {
    System.out.print((2*k)+" ");
    k++;
   }
   System.out.println();
  }
 }
}
1
3 3
5 5 5
7 7 7 7
SOLUTION :
class Test {
 public static void main(String[] a)
 {
  int k = 1;
  for(int i = 0; i< 4; i++) {
   for(int j = 0; j<=i; j++) {
    System.out.print((2*i+1)+" ");
   }
   System.out.println();
  }
 }
}
1
2 3
4 5 6
7 8 9 10
SOLUTION :
class Test {
 public static void main(String[] a)
 {
  int k = 1;
  for(int i = 1; i<= 4; i++) {
   for(int j = 1; j<=i; j++) {
    System.out.print(k+" ");
    k++;
   }
   System.out.println();
  }
 }
}
   1
  1 1
 1 2 1
1 3 3 1 
SOLUTION :
class Test {
 int fact(int x) {
  int res = 1;
  for(int i = 1; i < x; i++) {
   res = res*i;
  }
  return res;
 }
 void show() {
  int y;
  for(int i=0; i<=5; i++) {
   for(int c = 0; c<=(5-i-2); c++) {
    System.out.print(" ");
   }
   for(int c =0; c<= i; c++) {
    y =fact(i)/(fact(c)*fact(i-c));
    System.out.print(y+" ");
   }
   System.out.println();
  }
 }
 public static void main(String[] a)
 {
  Test t = new Test();
  t.show(); 
 }
}




CONTACT DETAILS

info@prowessapps.in
(8AM to 10PM):

+91-9026070669 , +91-9451396824

© 2016, prowessapps.in, All rights reserved