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 9009163
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T02:07:16+00:00 2026-06-16T02:07:16+00:00

How do I make this: ******* -*****- –***– —*— –***– -*****- ******* The following

  • 0

How do I make this:

*******
-*****-
--***--
---*---
--***--
-*****-
*******

The following is my code that I have written to try to accomplish the above, but it is not working as expected:

    public static void stars(/*int jmlBaris*/) {
    for ( int i = 7; i >= 1; i-=2) {
        for (int j = 1; j <= i; j++) {

            System.out.print("*");
        }
        System.out.println("");
    }

    for (int i = 1; i <= 7; i+=2) {
        for (int j = 1; j <= i; j++){
            System.out.print("*");
            }
        System.out.println("");
    }
}
public static void main(String[] args) {
    stars();
}
}
  • 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-06-16T02:07:17+00:00Added an answer on June 16, 2026 at 2:07 am

    This is how I might write it.

    // three loops
    public static void stars(int size) {
        for (int y = 0; y < size; y++) {
            for (int i = 0; i < y && i < size - y - 1; i++)
                System.out.print(' ');
            for (int i = Math.min(y, size - y - 1); i < Math.max(y + 1, size - y); i++)
                System.out.print('*');
            System.out.println();
        }
    }
    

    or

    // two loops
    public static void stars(int size) {
        for (int y = 0; y < size; y++) {
            for (int x = 0; x < size; x++)
                System.out.print(
                        (x >= y && x < size - y) ||
                                (x >= size - y - 1 && x <= y) ? '*' : ' ');
            System.out.println();
        }
    }
    

    or

    // one loop
    public static void stars(int size) {
        for (int i = 0; i < size * size; i++) {
            int y = i / size, x = i % size;
            System.out.print(
                    (x >= y && x < size - y) ||
                            (x >= size - y - 1 && x <= y) ? '*' : ' ');
            if (x == size - 1)
                System.out.println();
        }
    }
    

    Note: Whether this uses one, two or three loops, the time complexity is O(N^2). A simple way to determine this is the number of stars produced is O(N^2) no matter how it is done.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

To make this simple. I have some text that when you click on it.
I'll try to make this as simple a posible. I just started working with
I want to make this regex to support white spaces too but ( not
I wanted to make this script work somehow, but i find that after you
How do i make this code not to give error if he query is
help make this, the following code finds the txt files in the folder, and
I make this code that, after 9 seconds, it call an ajax function, and
Ill try and make this as clear as possible. I have a contact form
To make this example as simple as possible, let's say I have the following
I try to make this implementation of a multimap in C++, but I run

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.