Automation Using Selenium Webdriver
Showing posts with label Pattern Program in java Part-2. Show all posts
Showing posts with label Pattern Program in java Part-2. Show all posts

Wednesday, 30 November 2016

Pattern Program in java Part-2

#4 Java Program to print Numbers in Below pattern

1 2 3 4 5 6 7 8 9 
 1 2 3 4 5 6 7 8 
  1 2 3 4 5 6 7 
   1 2 3 4 5 6 
    1 2 3 4 5 
     1 2 3 4 
      1 2 3 
       1 2 
        1 
  1. package com.Java;
  2. public class NumbersFormat {
  3. public static void main(String[] args) {
  4.  
  5. int r, c1,c2;
  6.  
  7. for (r = 1; r <= 10; r++) {
  8.  
  9. for (c1 = 1; c1 <r; c1++) {
  10.   System.out.print(" ");
  11. }
  12.  
  13. for (c2 = 1; c2 <= 10 - r; c2++) {
  14.     System.out.print(c2 + " ");
  15. }
  16.  
  17. System.out.println("");
  18. }
  19.  
  20. }
  21.  
  22. }

Output:
  1. 1 2 3 4 5 6 7 8 9  
  2. 1 2 3 4 5 6 7 8 
  3.   1 2 3 4 5 6 7 
  4.    1 2 3 4 5 6 
  5.     1 2 3 4 5 
  6.      1 2 3 4 
  7.       1 2 3 
  8.        1 2 
  9.         1 




#5 Java Program to Print Numbers in Below pattern:

        1 
       1 2 
      1 2 3 
     1 2 3 4 
    1 2 3 4 5 
   1 2 3 4 5 6 
  1 2 3 4 5 6 7 
 1 2 3 4 5 6 7 8 
1 2 3 4 5 6 7 8 9 
1 2 3 4 5 6 7 8 9 10 


  1. package com.Java;
  2. public class NumbersFormat {
  3. public static void main(String[] args) {
  4.  
  5. int r, c1,c2;
  6.  
  7. for (r = 1; r <= 10; r++) {
  8.  
  9. for (c1 = 1; c1 <10-r; c1++) {
  10.   System.out.print(" ");
  11. }
  12.  
  13. for (c2 = 1; c2 <= r; c2++) {
  14.     System.out.print(c2 + " ");
  15. }
  16.  
  17. System.out.println("");
  18. }
  19.  
  20. }
  21.  
  22. }

Output:
  1.         1 
  2.        1 2 
  3.       1 2 3 
  4.      1 2 3 4 
  5.     1 2 3 4 5 
  6.    1 2 3 4 5 6 
  7.   1 2 3 4 5 6 7  
  8. 1 2 3 4 5 6 7 8 
  9. 1 2 3 4 5 6 7 8 9 
  10. 1 2 3 4 5 6 7 8 9 10