Share on Google+Share on Google+

Shinichi
Display patterns
2 Answer(s)      4 years and 4 months ago
Posted in : Java Beginners

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)

Ads

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.










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
design patterns are used in Struts?
design patterns are used in Struts?  What design patterns are used in Struts
Design Patterns
Design Patterns       Design Patterns: Patterns are solutions for the specific problem in a specific context.  (OR) Patterns are solutions to recurring problem
J2EE design patterns - Design concepts & design patterns
J2EE design patterns  Hi all, could any one send me design patterns links. its very utgent. thanks, lakshminarayana.  Hi Friend, For J2EE Singleton Pattern,visit the following link: http
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
Design patterns in ejb - EJB
Design patterns in ejb  Hi any any one send some links or material on design patterns in EJB iam toally new to this concept(i.e design patterns) ... of design patterns, strategies, and best practices for EJB design and development
Behavioral Patterns
Behavioral Patterns       Behavioral patterns are those patterns which are specifically... to avoid hard-coding and dependencies. The behavioral patterns are: 1. Chain
Design patterns - Design concepts & design patterns
Design patterns  I am new to design patterns and desigining . Please refer me some tutorial or pdfs of design patterns and desigining in easy language and understandable..so that i can apply it in my current project
design patterns - Java Beginners
design patterns  what are the design patterns used in java?  Hi Friend, Please visit the following links: http://www.roseindia.net/designpattern/index.shtml http://www.roseindia.net/javatutorials/J2EE_singleton
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
Relationship among Design patterns
Relationship among Design patterns       Patterns have relationships and work together... are with the different patterns, better you determine their interactions. Generally, to build
About desing patterns - Struts
About desing patterns  How many Design Patterns are there supported by Java? and what is an Application Controller? what is the difference between Front Controller & Application Contorller?  Hi Friend, Please visit
Categorizing Design Patterns
Categorizing Design Patterns       Patterns focus on different types of problems. Related patterns are grouped together and assigned a type. This helps programmers
Java - Design concepts & design patterns
Java  What are design patterens?  Hi friend, Software professionals may be familiar with the term "Design Patterns," but many have... not see the value and benefits design patterns bring to the software development
PHP Design Patterns
PHP Design Patterns: A design pattern is like a template which guides us to solve a problem. Design patterns are not finished design that can be transformed directly into code. In Object Oriented based design patterns we can get
patterns printing using for loop in java
patterns printing using for loop in java  how to write the code for the pattern as: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
DAO,DTO,VO Design patterns
DAO,DTO,VO Design patterns  explain dao,dto,vo design patterns in strut 1.3?   Data Access Object (DAO) pattern is the most popular design patterns. It is used when you want to separate your presentation code from
Display Problem
Display Problem  i am creating a small window application , i want to fetch data from ms-access(db) and want to display it on tables. what options are there to show result on table. is CSS helpfull
Display data
Display data  after successful login how i can fetch my account information from sql database
how to display?
how to display?  How to write a select query for displaying data where i have author as multivalued attribute
Tutorials   
Java Spring Hibernate Struts Training What does core Java include? java What are some way to learn Java quickly? Is it required to learn Java before learning Java Script? Is it necessary to learn java script before learning PHP? Are HTML5 and Java Script boosts Java career? Is Java object oriented? Fingerprint application with Java Uninstall Oracle Virtual Box JSON to HashMap Free Java online Training I want example of Control Statement in Java ANSI Color Codes with Python Create a Program that Calculates Input What is difference between JDK,JRE and JVM? How to see ubuntu version on server? How to get Page Source in Selenium (WebDriver) using Java? The path to the driver executable must be set by the webdriver.gecko.driver system property parse data from a link in java Java Program Qns using BlueJ How to fix HAX Kernel Module Is Not Installed error? Installing Audacity Looking for code Logic to check track changes & Coments in MSWord, MSWordx, MSExcel, MSExcelx is ON/OFF Installing JDK on Mac SAX Parser exception ERROR 601 (42P00): Syntax error. Encountered Thread java.lang.NoClassDefFoundError: org/apache/commons/fileupload/FileItemFactory How to install Ubuntu 16.04 LTS? HttpServletRequest cannot be resolved to a type in eclipse - Solved Unhandled event loop exception GC overhead limit exceeded Spring Data jpa with apache phoenix Caused by: java.lang.IllegalArgumentException: Not a host:port pair: PBUF o.a.h.h.z.RecoverableZooKeeper - Possibly transient ZooKeeper, quorum= com.thinkaurelius.titan.diskstorage.hbase.HBaseStoreManager class not found com.thinkaurelius.titan.diskstorage.hbase.HBaseStoreManager not found How to download and install Java 8 on Windows? How to uninstall JDK 7? How to install gtk-doc-tools package in Ubuntu? How to install Oracle JDK 8 on Ubuntu? ejabberd_ctl.beam not found - Solved How to convert date to UTC format in Java? How to install autoconf, automake and libtool in Ubuntu 15.10? How to convert current date to mm dd yyyy format in Java? How to convert current date to dd mm yyyy format in Java? How to stop window closing in "internalFrameClosing" event. How to find list of all index in Neo4j? neo4j-server.properties file location SASLError using PLAIN: not-authorized how to convert war file into .exe file using java code

Ads

 
Advertisement null

Ads