Display patterns

Display patterns

Write a test program that read an integer n and call a method to display a pattern as follows:

1

2 1

3 2 1

4 3 2 1

...

n n-1 ... 3 2 1

The method header is public static void displayPattern(int n)

View Answers

November 22, 2012 at 3:54 PM

Here is a code that displays the following pattern:

1 
2 1
3 2 1
4 3 2 1
5 4 3 2 1

class Pattern{
     public static void displayPattern(int n){
        for(int i=1;i<=n;i++){

            for(int j=i;j>=1;j--){
            System.out.print(j);
            }
            System.out.println();
           }
     }
     public static void main(String args[]){
          displayPattern(5);       
    }
}

November 22, 2012 at 4:27 PM

thank you.really appreciate that.

Ads









Related Tutorials/Questions & Answers:
Display patterns
Display patterns  Write a test program that read an integer n and call a method to display a pattern as follows: 1 2 1 3 2 1 4 3 2 1 ... n n-1 ... 3 2 1 The method header is public static void displayPattern(int n)   
Display patterns
Display patterns  Write a test program that read an integer n and call a method to display a pattern as follows: 1 2 1 3 2 1 4 3 2 1 ... n n-1 ... 3 2 1 The method header is public static void displayPattern(int n)  
Advertisements
Display Date and Time - Design concepts & design patterns
Display Date and Time  HI, Can u send me Html code displaying system date and time . Thanks Prakash  Hi Friend, Try the following code: System Date and Time var date = new Date(); document.write
patterns
patterns  who ever answered my previous ques thank u sooooo much!!!!!!!!!! though i was able to solve most complicated progms in java patterns are a night mare for me. thank u once again.can u help me on how to print
Patterns
Patterns       Why Use Patterns?    They have been proven. Patterns reflect... used these patterns in their own work.     They are reusable
display
display  please tell me how to display the content from database.. if we click on any image using servlets/jsp...please
AJAX Patterns
AJAX Patterns       The publicly editable repository of all things Ajax. Design Patterns, Frameworks, Libraries, Tools and Links Read full Description
patterns
patterns
patterns
patterns
Patterns
ModuleNotFoundError: No module named 'patterns'
ModuleNotFoundError: No module named 'patterns'  Hi, My Python... 'patterns' How to remove the ModuleNotFoundError: No module named 'patterns... to install padas library. You can install patterns python with following
ModuleNotFoundError: No module named 'patterns'
ModuleNotFoundError: No module named 'patterns'  Hi, My Python... 'patterns' How to remove the ModuleNotFoundError: No module named 'patterns... to install padas library. You can install patterns python with following
ModuleNotFoundError: No module named 'patterns'
ModuleNotFoundError: No module named 'patterns'  Hi, My Python... 'patterns' How to remove the ModuleNotFoundError: No module named 'patterns... to install padas library. You can install patterns python with following
Design Patterns
Design Patterns       Design Patterns: Patterns are solutions for the specific problem in a specific context.  (OR) Patterns are solutions to recurring problem
Creational Patterns
Creational Patterns   This design category is all about the class instantiation. Creational pattern uses class-creation patterns and object-creational patterns. The class-creation pattern uses inheritance
Behavioral Patterns
Behavioral Patterns       Behavioral patterns are those patterns which are specifically... to avoid hard-coding and dependencies. The behavioral patterns are: 1. Chain
Structural Patterns
Structural Patterns   Structural Patterns Structural Patterns describe how objects and classes can be combined to form larger structures. The difference between class patterns and object patterns
Version of com.ft>functional-patterns dependency
List of Version of com.ft>functional-patterns dependency
ModuleNotFoundError: No module named 'common-patterns'
ModuleNotFoundError: No module named 'common-patterns'  Hi, My... named 'common-patterns' How to remove the ModuleNotFoundError: No module named 'common-patterns' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'diamond-patterns'
ModuleNotFoundError: No module named 'diamond-patterns'  Hi, My... named 'diamond-patterns' How to remove the ModuleNotFoundError: No module named 'diamond-patterns' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'async-patterns'
ModuleNotFoundError: No module named 'async-patterns'  Hi, My... named 'async-patterns' How to remove the ModuleNotFoundError: No module named 'async-patterns' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'common-patterns'
ModuleNotFoundError: No module named 'common-patterns'  Hi, My... named 'common-patterns' How to remove the ModuleNotFoundError: No module named 'common-patterns' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'data-patterns'
ModuleNotFoundError: No module named 'data-patterns'  Hi, My... 'data-patterns' How to remove the ModuleNotFoundError: No module named 'data-patterns' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'design-patterns'
ModuleNotFoundError: No module named 'design-patterns'  Hi, My... named 'design-patterns' How to remove the ModuleNotFoundError: No module named 'design-patterns' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'diamond-patterns'
ModuleNotFoundError: No module named 'diamond-patterns'  Hi, My... named 'diamond-patterns' How to remove the ModuleNotFoundError: No module named 'diamond-patterns' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'diamond-patterns'
ModuleNotFoundError: No module named 'diamond-patterns'  Hi, My... named 'diamond-patterns' How to remove the ModuleNotFoundError: No module named 'diamond-patterns' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'django-patterns'
ModuleNotFoundError: No module named 'django-patterns'  Hi, My... named 'django-patterns' How to remove the ModuleNotFoundError: No module named 'django-patterns' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'exploit-patterns'
ModuleNotFoundError: No module named 'exploit-patterns'  Hi, My... named 'exploit-patterns' How to remove the ModuleNotFoundError: No module named 'exploit-patterns' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'python-patterns'
ModuleNotFoundError: No module named 'python-patterns'  Hi, My... named 'python-patterns' How to remove the ModuleNotFoundError: No module named 'python-patterns' error? Thanks   Hi, In your python

Ads