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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T09:50:44+00:00 2026-05-25T09:50:44+00:00

private int array[][] = new int[5][5]; private void arrayIteration(){ for(int i = 0; i

  • 0
private int array[][] = new int[5][5];

private void arrayIteration(){
    for(int i = 0; i < array.length; i++){
        for(int j = 0; j < array.length; j++){
            array[i][j] = 10;
        }
    }
}

Can I change the iteration method to recursive one that does the same task?

Edit (this is what I’ve tried but it’s just playing with what I want to do):

private void arrayRecursion(){
    if(){
        array[i][i] = 10;  // Base
        return;
    }
    for(int i = 0; i < array.length; i++){
        arrayRecursion();
    }
}
  • 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-05-25T09:50:44+00:00Added an answer on May 25, 2026 at 9:50 am

    Here’s one way you could do it. Basically you start in the 0,0 corner and set it to the value. Then you do 0,1 and 1,0. 0,1 will set, and do 1,1 and 1,2. 1,0 will set and do 2,0 and 1,1. Note that 1,1 just got hit twice – that’s fine because it’s overwriting what it did before. When it hits a ‘wall’ it stops (this means if the [3] array was null, [4] wouldn’t get hit) but that isn’t a problem for arrays allocated with new int[x][y] notation.

    class Sandbox {
        public static void main(String[] args) {
            int[][] test = new int[5][5];
            recursiveAssign(test,10);
            int numThatAreTen = 0;
            for(int i = 0; i < 5; i++) {
                for(int j = 0; j < 5; j++) {
                    if(test[i][j] == 10) numThatAreTen++;
                }
            }
            System.out.println(numThatAreTen);
        } // main
    
        static void recursiveAssign(int[][] arr, int value) {
            recursiveAssign0(arr,value,0,0);
        } // recursiveAssign
    
        static private void recursiveAssign0(int[][] arr, int value, int x, int y) {
            if(arr != null && x < arr.length && arr[x] != null && y < arr[x].length) {
                arr[x][y] = value;
                // now go down, and across
                recursiveAssign0(arr,value,x+1,y);
                recursiveAssign0(arr,value,x,y+1);
            } 
        } // recursiveAssign0
    
    } // Sandbox
    

    which prints the expected 25

    C:\Documents and Settings\glowcoder\My Documents>javac Sandbox.java
    
    C:\Documents and Settings\glowcoder\My Documents>java Sandbox
    25
    
    C:\Documents and Settings\glowcoder\My Documents>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

private int GetNextId() { SQLiteConnector conn = new SQLiteConnector(false); conn.OpenConnection(); cmd = new SQLiteCommand(SELECT
public class Ex7 { private int fld; private void meth(int val) { fld =
I have following class public class ButtonChange { private int _buttonState; public void SetButtonState(int
In the context of C++ (not that it matters): class Foo{ private: int x[100];
public class DrawView extends View { private ColorBall[] colorballs = new ColorBall[3]; // array
I'm totally new to C# and I'm having an error that I can't guess
I'm creating an array of BackgroundWorker that shares one event handler like this: BackgroundWorker[]
#include iostream class A { private: int a; public : A(): a(-1) {} int
public class Arrys { private int[] nums; //Step 3 public Arrys (int arrySize) {
public class PlayText extends Thread { private int duration; private String text; private PlayerScreen

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.