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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T10:44:36+00:00 2026-06-02T10:44:36+00:00

Everytime I call set() it resets all the values in the array to false

  • 0

Everytime I call set() it resets all the values in the array to false except for what ever the int row int col is because i set that to true before the method ends. Why is this happening I thought I was making a copy of the array B and then setting the values that are in A to the values in B? Or am I mistaken here.

public void set(int row, int col) throws IndexOutOfBoundsException {
    if (row >capacityr) {            
        boolean B[][] = new boolean[row+1][capacityc+1];
        for (int k = 0; k < capacityr; k++) 
            for (int j = 0; j < capacityc; j++) 
                B[k][j] = a[k][j];                

        capacityr=row;
        a = B;
    }

    if (col >capacityc) {            
        boolean C[][] = new boolean[capacityr+1][col+1];
        for (int k = 0; k <capacityr; k++) 
            for (int j = 0; j < capacityc; j++) 
                C[k][j] = a[k][j];                

        capacityc=col;
        a = C;
    }       

    a[row][col] = true;
    pT++;                   
}            
  • 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-02T10:44:38+00:00Added an answer on June 2, 2026 at 10:44 am

    It should be easier to use an ArrayList but I think this would fix your problem.

    public void set(int row, int col) throws IndexOutOfBoundsException {
       if(row > capacityr) {
          if(col > capacityc) {
             //both row and col are too big
             boolean temp[][] = new boolean[row+1][col+1];
    
             //copy a
             for(int i = 0; i <= capacityr; i++) {
               for(int j = 0; j <= capacityc; j++) {
                  temp[i][j] = a[i][j];
               }
             }
    
             //set all the new elements to false
             for(int i = capacityr+1; i <= row; i++) {
               for(int j = capacityc+1; j <= col; j++) {
                  temp[i][j] = false;
               }
             }
    
             //set row and col and a to temp
             temp[row][col] = true;
             a = temp;
    
             //update capacity
             capacityr = row;
             capacityc = col;
          }
          else {
             //just row is too big
             boolean temp[][] = new boolean[row+1][capacityc+1];
             for(int i = 0; i <= capacityr; i++) {
               for(int j = 0; j <= capacityc; j++) {
                  temp[i][j] = a[i][j];
               }
             }
    
             for(int i = capacityr+1; i <= row; i++) {
                 temp[i][capacityc] = false;
             }
             temp[row][col] = true;
             a = temp;
             capacityr = row;
          }
      }
      else {
         if(col > capacityc) {
            //just col is too big
            boolean temp[][] = new boolean[capacityr+1][col+1];
            for(int i = 0; i <= capacityr; i++) {
               for(int j = 0; j <= capacityc; j++) {
                   temp[i][j] = a[i][j];
               }
            }
    
            for(int j = capacityc+1; j <= col; j++) {
                 temp[capacityr][j] = false;
            }
            temp[row][col] = true;
            a = temp;
            capacityc = col;
         }
         else {
            //neither are too big
            a[row][col] = true;
         }
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Coming from C++ it is hard grained into my mind that everytime I call
I have this class that everytime I call the constructor should increment the id
In my app, everytime it go in background I want set all classes at
I want to generate unique id's everytime i call methode generateCustumerId(). The generated id
i'am working on an autogrowing listview. Everytime before i call mAdapter.notifyDataSetChanged(); i toggle the
Do I need to call edit SharedPreferences everytime before I change the preferences and
Everytime the program loads, I need a dictionary to have about 15 values. Right
I have a utility method (= a static one) that I call a lot,
Everytime call this stored procedure i get this error: #1064 - You have an
Is there a way to define a method, which is called everytime I call

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.