Answers for "pyramid pattern program in java"

0

java pyramid pattern

import java.util.Scanner;
public class Edureka
{
      
public static void main(String[] args) 
{
Scanner sc = new Scanner(System.in);
      
System.out.println("Enter the number of rows: ");
 
int rows = sc.nextInt();
          
for (int i = 1; i <= rows; i++) { for (int j = i; j >= 1; j--)
   {
       System.out.print(j+" ");
   }
     
   System.out.println();
}         
sc.close();
}
}
Posted by: Guest on September-16-2021
0

java pyramid pattern

import java.util.Scanner;
public class Edureka
{
      
public static void main(String[] args) 
{
Scanner sc = new Scanner(System.in);
      
System.out.println("Enter the number of rows: ");
 
int rows = sc.nextInt();
          
for (int i = 1; i <= rows; i++) { for (int j = i; j >= 1; j--)
   {
       System.out.print(j+" ");
   }
     
   System.out.println();
}         
sc.close();
}
}
Posted by: Guest on September-16-2021
-1

pyramid pattern in java

// Java implementation to print the 
// following pyramid pattern 
public class Pyramid_Pattern { 
  
    // function to print the following pyramid 
    // pattern 
    static void printPattern(int n) 
    { 
        int j, k = 0; 
  
        // loop to decide the row number 
        for (int i = 1; i <= n; i++) { 
              
            // if row number is odd 
            if (i % 2 != 0) { 
              
                // print numbers with the '*'  
                // sign in increasing order 
                for (j = k + 1; j < k + i; j++) 
                    System.out.print(j + "*"); 
                System.out.println(j++); 
  
                // update value of 'k' 
                k = j; 
            } 
  
            // if row number is even 
            else { 
                 
                // update value of 'k' 
                k = k + i - 1; 
  
                // print numbers with the '*' in 
                // decreasing order 
                for (j = k; j > k - i + 1; j--) 
                    System.out.print(j + "*"); 
                System.out.println(j); 
            } 
        } 
    } 
  
    // Driver program to test above 
public static void main(String args[]) 
    { 
        int n = 5; 
        printPattern(n); 
    } 
}
Posted by: Guest on January-22-2021
-1

pyramid pattern in java

// Java implementation to print the 
// following pyramid pattern 
public class Pyramid_Pattern { 
  
    // function to print the following pyramid 
    // pattern 
    static void printPattern(int n) 
    { 
        int j, k = 0; 
  
        // loop to decide the row number 
        for (int i = 1; i <= n; i++) { 
              
            // if row number is odd 
            if (i % 2 != 0) { 
              
                // print numbers with the '*'  
                // sign in increasing order 
                for (j = k + 1; j < k + i; j++) 
                    System.out.print(j + "*"); 
                System.out.println(j++); 
  
                // update value of 'k' 
                k = j; 
            } 
  
            // if row number is even 
            else { 
                 
                // update value of 'k' 
                k = k + i - 1; 
  
                // print numbers with the '*' in 
                // decreasing order 
                for (j = k; j > k - i + 1; j--) 
                    System.out.print(j + "*"); 
                System.out.println(j); 
            } 
        } 
    } 
  
    // Driver program to test above 
public static void main(String args[]) 
    { 
        int n = 5; 
        printPattern(n); 
    } 
}
Posted by: Guest on January-22-2021
-1

java pyramid pattern

1
      2 3 2
    3 4 5 4 3
  4 5 6 7 6 5 4
5 6 7 8 9 8 7 6 5
Posted by: Guest on September-16-2021
-1

java pyramid pattern

1
      2 3 2
    3 4 5 4 3
  4 5 6 7 6 5 4
5 6 7 8 9 8 7 6 5
Posted by: Guest on September-16-2021

Code answers related to "pyramid pattern program in java"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language