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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T20:32:16+00:00 2026-05-27T20:32:16+00:00

So basically the problem is that I have segment of code that needs to

  • 0

So basically the problem is that I have segment of code that needs to be re-used with very slight variations through out in a java method.

This section of code also needs access to a variable only defined within the class method.

I did a search, but found no way that I can add a subroutine within a method. I thought about adding a local class, but it seems you can’t use static methods with these, which is what I really need.

If it helps at all, my goal is to initialise a gameboard, that basically consists of:

GameSquare[][] board = new GameSquare[15][15];

and for each call:

board[a][b] = new GameSquare(params);

there should be a corresponding call for:

board[b][a] = new GameSquare(params);
board[15-a][15-b] = new GameSquare(params);
board[15-b][15-a] = new GameSquare(params);

Ie any special square needs to mirrored across the other four corners.

I’m hoping to have all these included within a single method. If there were a way to have an method within a method, I could just have:

method( int a, int b, otherparams passed to GameSquare constructor){
  //initialise those 4 squares.
}

But, so far I have not found such a way of doing this.

Cheers.

  • 1 1 Answer
  • 2 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-05-27T20:32:17+00:00Added an answer on May 27, 2026 at 8:32 pm

    Since it’s an array, how about just passing the array as a parameter to the method? Except for primitives (int, float, etc.), parameters in Java are passed by reference so you are still modifying the same array.

    method(GameSquare[][] board, int a, int b, otherparams passed to GameSquare constructor){
        board[a][b] = new GameSquare(params)
        board[b][a] = new GameSquare(params)
        board[15-a][15-b] = new GameSquare(params)
        board[15-b][15-a] = new GameSquare(params)
    }
    

    Using it:

    GameSquare[][] board = new GameSquare[15][15];
    method(board,a,b,params);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is a very open question about a problem that we have. Basically, we
I have a pretty simple problem. Basically I have an array called $list that
Basically my problem is that i've adapted a piece of code found here http://social.msdn.microsoft.com/Forums/en-US/vemapcontroldev/thread/62e70670-f306-4bb7-8684-549979af91c1
This is basically a math problem, but very programing related: if I have 1
I have problem that how to change text inside the progressdialog (basically having STYLE_HORIZONTAL
I have some localization problems in my webpage. There are basically two problems (that
Basically my problem stems from a desire to have the textbox portion be white,
The problem is basically this, in python's gobject and gtk bindings. Assume we have
I have basically the same problem outlined in this question, however I am using
I have added respond.js to activate media queries in ie7+8, the problem that Im

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.