OCJP

Pattern Program using Java

As we have learnt so many Pattern Programs using C Language, Now We are going to explain a Pattern Program of Multiple Pyramid using Java Code. Here we have used Nesting of For Loops and If conditions.


/**
 *
 * @author Jadeja
 */
public class Pattern {

public static void main(String []a){
    
    for(int i=1;i<=10;i++){
        
        
        for(int j=1;j<=i;j++){
            System.out.print(" ");
        }
        for(int j=1;j<=21;j++){
        
            if(j<= 11-i)
                System.out.print("O  ");
            else if (j<=10+i)
                System.out.print("MM");
            else 
                System.out.print(" E ");
        }
        
       
        System.out.println();
    }
}    
}

Output of the Program

Multiple Pyramids Pattern using Java Code

As we have used Java Language for the same but it can also be written using C or C++ Language.

Leave a Reply

Your email address will not be published. Required fields are marked *


× How can I help you?