Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3405598
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T05:31:30+00:00 2026-05-18T05:31:30+00:00

___________1 __________1 2 1 _________1 2 3 2 1 ________1 2 3 4 3

  • 0
___________1
__________1 2 1
_________1 2 3 2 1
________1 2 3 4 3 2 1
______1 2 3 4 5 4 3 2 1
_____1 2 3 4 4 4 4 4 3 2 1
___1 2 3 3 3 3 3 3 3 3 3 2 1
__1 2 2 2 2 2 2 2 2 2 2 2 2 2 1
_1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1

I would like to create this pyramid using java? Any suggestion?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T05:31:31+00:00Added an answer on May 18, 2026 at 5:31 am

    This will surve the purpose. You can change the number 5 to another number other than 5. eg. 1,2,3,.. , 6,8

    public static void main(String[] args) {
    
    
        List<String> list = new LinkedList<String>();
    
        for(int i = 5; i > 0; i-- ){
            wrapWithNumber(list, i);
        }
    
    
        for (String string : editListToBeInTriangleShape(list)) {
            System.out.println(string);
        };
    }
    
    /**
          * Wrap the number strings in the llist with a perticular number.
     * @param list list of Strings
     * @param ba number which need to wrapp the list with.
     */
    private void wrapWithNumber(List<String> list, final int ba) {
    
        list.add(0, String.format("%d",ba));
    
        for (int i = 1; i < list.size(); i++) {
            String newformat = "%1$d " + list.get(i) + " %1$d";
            list.remove(list.get(i));
            list.add(i,String.format(newformat, ba));
        }
    
        String lastFormat = "%1$d";
        for(int i = 0; i < 2 * list.size();i++){
            lastFormat += " %1$d";
        }
    
        if(list.size() != 1) {
            list.add(String.format(lastFormat, ba));
        }
    }
    
    /**
     * Arrage the Strings in the list in triangular manner.
     * @param list list of Strings.
     */
    private List<String> editListToBeInTriangleShape(final List<String> list) {
    
        final List<String> returnList = new LinkedList<String>();
    
        for (int i = list.size(); i > 0; i--) {
            String s = list.get(list.size()-i);
            int possition = list.size()*2 + s.length()/2;
            returnList.add(String.format("%"+possition+"s", s));
        }
    
        return returnList;
    }
    

    out put of this :

                     1
                   1 2 1
                 1 2 3 2 1
               1 2 3 4 3 2 1
             1 2 3 4 5 4 3 2 1
           1 2 3 4 4 4 4 4 3 2 1
         1 2 3 3 3 3 3 3 3 3 3 2 1
       1 2 2 2 2 2 2 2 2 2 2 2 2 2 1
     1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using the new CakePHP 2.1 and would like to use the JsonView to
I have a string Like this: MyText (1,151) I would like to get with
I am using Ruby on Rails 3.1 and I would like to order a
I've made a small 3D viewer application using DirectX 9.0. Now I would like
I am using Rails 3.1.1 and I would like to redirect users, for example,
I am using Rails 3.1.1 and I would like to recognize (maybe using a
I'm building a web mobile app, using jQuery 1.1.1 and HTML5. I would like
Question 1 We would like to generate a site map for our CMS site
I am playing with Zend 1.9 and would like to have the language parameter
In Joomla 1.5 I would like to have a startpage (that has its own

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.