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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T09:26:47+00:00 2026-06-14T09:26:47+00:00

The problem I am having is when I print out horizontalLine(1, 1, 3, 1)

  • 0

The problem I am having is when I print out horizontalLine(1, 1, 3, 1) it adds the horizontalLine before it into the console. Is there any way to stop the duplication?

public class Array {

static String arrayPicture[][];

public static void main (String[] args) {

    arrayPicture = new String [5][5];

    for (int i = 0; i < 5; i ++) {

        for (int j = 0; j < 5; j ++) {
            arrayPicture [i][j] = " ";
    }
}
        horizontalLine (0, 0, 4, 0);
        horizontalLine (1, 1, 3, 1);
}
public static void horizontalLine (int x1, int y1, int x2, int y2) {

            for (int k = x1; k < x2; k ++) {
                arrayPicture [y1][k] = "*";
            }
            picture();
            System.out.println ();
}
public static void picture () {
            for (int i = 0; i < 5; i ++) {

            for (int j = 0; j < 5; j ++) {
                System.out.print (arrayPicture[i][j]);
                }
            }
        }
}
  • 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-14T09:26:48+00:00Added an answer on June 14, 2026 at 9:26 am

    All happens in the picture() method because in order to print the second array, your index restarts to 0 …

    Here a solution, note the argument for the picture() method:
    (even if the code is originally not well readable)

    class Array {
    
        static String arrayPicture[][];
    
        public static void main(String[] args) {
    
            arrayPicture = new String[5][5];
    
            for (int i = 0; i < 5; i++) {
    
                for (int j = 0; j < 5; j++) {
                    arrayPicture[i][j] = " ";
                }
            }
            horizontalLine(0, 0, 4);
            horizontalLine(1, 1, 3);
        }
    
        public static void horizontalLine(int x1, int y1, int x2) {
    
            for (int k = x1; k < x2; k++) {
                arrayPicture[y1][k] = "*";
            }
            picture(y1);
            System.out.println();
        }
    
        public static void picture(int startIndex) {
            for (int i = startIndex; i < 5; i++) { // start from startIndex, not necessary 0 !
                for (int j = 0; j < 5; j++) {
                    System.out.print(arrayPicture[i][j]);
                }
            }
        }
    }
    

    Output:

    ****                     
     ** 
    

    (I removed y2 argument since not used within your actual code)

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

Sidebar

Related Questions

I'm having a problem with getting this code to print out to file due
I having problem to print out check box according to booth and total days.
I'm having a problem with this piece of PHP. It's meant to print out
Having a problem converting loop output into an array. I am converting a decimal
I am having a problem I can't seem to figure out and I hope
Just wondering if some one could help me out. The problem I'm having is
I'm having a bit of a problem when it comes to printing out this
I am having a problem when trying to programmatically print a directory of word
I'm having a very odd problem that I can't seem to track down. Any
Im having problems with displaying ONLY some elements ONLY on print page. For example

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.