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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T19:04:28+00:00 2026-06-14T19:04:28+00:00

I’ve got an issue where it’s not printing out like it should and cannot

  • 0

I’ve got an issue where it’s not printing out like it should and cannot figure out what it is.

right now my code is printing out this:

***#

***##

***###

when it should be printing out like this:

***#

**##

*###

Here’s my code as it stands now:

import static java.lang.System.*;

public class Box
{
  private int size;

public Box()
{




}

public Box(int count)
{
    size = count;
}

public void setSize(int count)
{
    size = count;
}

public int getSize()
{
    return size;
}

public String toString()
{
    String output="";
    for(int i = 1; i <= size; i++)
    {
        for(int k = size; k >0; k--)
        {
            output += "*";
        }
        for(int j = size; j >size-i; j--)
        {
            output += "#";
        }
        output += "\n"; 
    }
    
    return output;
}
}

and my runner class for cross-referencing:

import static java.lang.System.*;

import java.util.Scanner;

public class Lab11e
{
 public static void main( String args[] )
 {
   Scanner keyboard = new Scanner(System.in);
    String choice="";
        do{
            out.print("Enter the size of the box : ");
            int big = keyboard.nextInt();
            //out.print("Enter a letter : ");
            //String value = keyboard.next();

                //instantiate a TriangleFour object
         Box box = new Box( big);
            //call the toString method to print the triangle
            System.out.println( box );

            System.out.print("Do you want to enter more data? ");
            choice=keyboard.next();
        }while(choice.equals("Y")||choice.equals("y"));
}
}

My thoughts are that I’m very close to getting it but just can’t figure out what.

  • 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-14T19:04:30+00:00Added an answer on June 14, 2026 at 7:04 pm
        for(int i = 1; i <= size; i++)
        {
            // Using a single for to make sure we don't create too many items.
            // Also note the +1. It seems that when size = 3, you want 4 chars
            // per line, so this take that extra char into account.
            for(int k = 0; k < size + 1; k++)
            {
                // Use an if to decide if we print * or #.
                    // As 'i' gets bigger, we need to put less *, so
                    // we subtract 'i' from the total size. This tells
                    // when the midpoint has passed and we should start
                    // writing #s.
                if (k <= size - i)
                    output += "*";
                else
                    output += "#";
            }
    
            output += "\n"; 
        }
    

    Solution with two inner loops:

        for(int i = 1; i <= size; i++)
        {
            // Adds a number of * inversely proportional to the current
            // value of 'i'.
            for(int k = 0; k <= size - i; k++)
            {
                output += "*";
            }
    
            // Start adding # where we stopped the *.
            for(int j = size - i; j < size; j++)
            {
                output += "#";
            }
    
            output += "\n"; 
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I know there's a lot of other questions out there that deal with this
I'm not entirely sure how I managed to jack this up. http://pretty-senshi.com If you

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.