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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T20:33:25+00:00 2026-06-18T20:33:25+00:00

writing some simple ASCII thing which basically for now is just printing out a

  • 0

writing some simple ASCII thing which basically for now is just printing out a char for each pixel with a defined width and height.

i have a for loop that adds the chars to a string and adds “\n” when width is reached so that width and height are correct.

however its currently printing one too many on first line and one too few on the last any ideas??

passing this to the method ('.', 7,5)

private String format(char character, int width, int height)
{
    char[] picture = new char[width * height];
    String pic = "";

    for(int i = 0; i < width * height; i++)
    {
        picture[i] = character;
        pic += picture[i];

        if(i == width || i > width  && i % width == 0)
        {
            pic += "\n";

        }
    }
    return pic;
}

and this is my output

……..
…….
…….
…….
……

ok well each block of those dots are meant to be on different lines but for some reason its putting them in a row, anyway you can still see that first row has 8 and last row has 6?

  • 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-18T20:33:26+00:00Added an answer on June 18, 2026 at 8:33 pm

    Just move your new-line appending up in the loop:

    if(i > 0 && (i % width) == 0)
    {
        pic += "\n";
    }
    picture[i] = character;
    pic += picture[i];
    

    and you should definitely use a StringBuilder for building strings.

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

Sidebar

Related Questions

I'm writing some code which could really do with some simple compile time metaprogramming.
I am learning Haskell, so I'm writing some simple card games. I've defined some
I'm writing some simple point code while trying out Visual Studio 10 (Beta 2),
I am writing some simple login scripts. I am just wondering, is there any
I was just writing some simple code and I noticed that using document.writeln doesn't
I'm writing some simple queries which return a single value and I'd like to
I'm writing a chrome extension that do some simple stuff. now, I made a
I'm writing an application which reads large arrays of floats and performs some simple
I'm writing some simple DAOs in Java using JDBC (no Spring, Hibernate or anything
I am trying to start writing some simple jQuery plugins and for my first

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.