A PHP Error was encountered

Severity: Warning

Message: fopen(/tmp/ci_session8uco81qjcuus15a2idekuvf52dcp8c8h): failed to open stream: No space left on device

Filename: drivers/Session_files_driver.php

Line Number: 176

Backtrace:

File: /var/www/html/application/controllers/Project.php
Line: 10
Function: __construct

File: /var/www/html/index.php
Line: 311
Function: require_once

A PHP Error was encountered

Severity: Warning

Message: session_start(): Failed to read session data: user (path: /tmp)

Filename: Session/Session.php

Line Number: 143

Backtrace:

File: /var/www/html/application/controllers/Project.php
Line: 10
Function: __construct

File: /var/www/html/index.php
Line: 311
Function: require_once

Print a Reverse Pyramid pattern in Java programming. | sohailkalyani
Coders Packet

Print a Reverse Pyramid pattern in Java programming.

By Sohail Chand Kalyani

In this Java tutorial we are going to solve the Reverse Pyramid triangle pattern using the concept of nested for loop.

Java pattern's questions are often asked in interview to check the coding skills,logic and looping concept.

To print the following pattern we will be required 3 for loop's,first one to print the spaces,second and third to print the star's.

So with the combination of this nested loop we can acheive Reverse or Inverted Pyramid pattern.

Inverted Triangle Star Pattern.

class Inverted_Pyramid {
    public static void main(String[] args) {
        
        for(int i=1;i<=8;i++){
            for (int j=1;j<i;j++){
                //for loop to print space's
                System.out.print(" ");
            }
            for(int k=8;k>=i;k--){
                //for loop to print star's
                System.out.print("*");
            }
            for(int l=7;l>=i;l--){
                //for loop to print star's
                System.out.print("*");
            }
            //after successful iteration the cursor will point at next line.
            System.out.println();
        }

    }

}

OUTPUT :

***************
  *************
    ***********
      *********
        *******
          *****
            ***
              *

Hope you understood the concept and code clearly,if not do comment below .

Download Complete Code

Comments

No comments yet

Download Packet

Reviews Report

Submitted by Sohail Chand Kalyani (sohailkalyani)

Download packets of source code on Coders Packet