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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T02:27:27+00:00 2026-06-13T02:27:27+00:00

public void printStars(int level) { for (int one = level; one >= 1; one–)

  • 0
public void printStars(int level) {

    for (int one = level; one >= 1; one--) {

        for (int two = one; two <= level; two++) {


            System.out.print("*");

        }
        System.out.println();


    }
}

I am trying to make something that looks like this:

    *
   ***
  *****
 *******
*********

Currently I am getting about half of the correct diagram all left aligned.

I tried to incorporate printf, but I realized that it wouldn’t work because the value of level cannot be transferred to the printf method. I was also wondering if there was a way to set the longest segment (the bottom) equal to (2 * level) – 1 stars long and apply some sort of formatting on that to get the answer?

  • 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-13T02:27:28+00:00Added an answer on June 13, 2026 at 2:27 am

    Print appropriate number of spaces ahead

    public void printStars(int level) {
    
        for (int one = level; one >= 1; one--) {
            for(int k=1, k<one;k++){  // print appropriate number of spaces before
                System.out.print(" "); 
            }    
            for (int two = 1; two <=2*(level-one)+1; two++) {
                System.out.print("*");
            }
            System.out.println();
        }
    }
    

    Explanation:

    1. if there are N levels in total, and last line doens’t have any space. => N-1 levels will have spaces with N-1 in first line, N-2 in 2nd line, so on.. 1 in (N-1)th line.

    2. Number of stars: (level-one) gives the line you are printing minus 1, because, initially when one = level (one-level = 0), its 1st line, next its (level-one) = 1, because one is decreased. & in each line you have to print, 2*X +1 *’s,

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

Sidebar

Related Questions

public void onCallStateChanged(int state,String incomingNumber) { System.out.print(\nState :- +state); switch(state){ case TelephonyManager.CALL_STATE_IDLE: if(flag==true &&
public void dataAnalytics() { double sum=0; System.out.println(dataAnalytics for the Rural region); for (Record ee
public void dataAnalytics() { double sum=0; double i=0; double minage=20; double maxage=20; System.out.println(dataAnalytics for
public void printList( ){ Node<E> p ; System.out.printf( [ ) ; for ( p=head.next
public void openOptions() { Intent intent=new Intent(this,Game.class); //intent.putExtra(razmer, level); startActivity(intent); // Intent intent=new Intent(this,Options.class);
public void setPunt(int index){ if(index >= 0 && index < PuntenLijst.size()){ x = 3;
public void Foo(IRB inR) { Stopwatch sw = new Stopwatch(); sw.Start(); System.Threading.Thread theThread =
public void setRange(int which) { if (datelimitsset == 1) { if (startPicker.Value >= endPicker.Value
public void Draw(SpriteBatch theSpriteBatch) { Random rand = new Random(); for(int y = 0;
public void writeToParcel(Parcel parcel, int flags) throws IOException { doSomethingThatThrowsIOException(); } Quoth the compiler:

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.