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

  • Home
  • SEARCH
  • 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 8788845
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T22:14:20+00:00 2026-06-13T22:14:20+00:00

This is for my homework: How to create a public method called cage(char[][] arr)

  • 0

This is for my homework: How to create a public method called cage(char[][] arr) that returns a char[][]. The method should place Xs along the borders of the grid represented by the 2D array. In addition, it should place “bars” along the columns of the array, skipping one column for every bar. For example, if arr has 8 columns, the returning array looks like this:

 X X X X X X X
 X   X   X   X
 X   X   X   X
 X X X X X X X

my other shape was this: Create a java class ArrayArt with static methods as specified below:
a public method called frame(char[][] arr) that returns a char[][]. The method should put Xs along the borders of the grid represented by the 2D array and then it should return that array. For example, if arr has 4 columns and 4 rows, the resulting array should be:

 ----jGRASP exec: java ArrayArt

  X X X X
  X     X
  X     X
  X X X X

 ----jGRASP: operation complete.

The source code for the frame printing is next:

 public class  ArrayArt{
    public static void main(String[] args){ 
        printArray(frame(4,4));

}

// frame printing
public static char[][] frame(int n, int m ){
    char[][] x=new char[n][m];

    for(int row=0;row<x.length;row++)
        for(int col=0;col<x[row].length;col++)
            if( row == 0 || row == n-1 || row == col+row || row == (row+col)-(m-1) )
                x[row][col]= 'X';
            else
                x[row][col]= ' ';

    return x;       
}

//printArray        
public static void printArray(char[][] arr){
    for(int row=0;row<arr.length;row++){
            for (int col=0;col<arr[row].length;col++)
                System.out.print(" "+arr[row][col]);
            System.out.println();

}
}

}
  • 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-13T22:14:21+00:00Added an answer on June 13, 2026 at 10:14 pm

    Just add this code after your else condition:

    for(int i=1;i<x[row].length;i++)if(col == i*2)x[row][col]= 'X';
    

    That shood do it! Good luck!

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

Sidebar

Related Questions

this is my homework that I need to create a generic method to calculate
So for Homework I have to create this program that reads from a text
I'm working on this homework that's kind of confusing me... I am provided with
I have this homework that I gotta finish, but then something about it is
For homework, I'm trying to create a CustomButton that has a frame and in
I'm working on a homework assignment that asks me to create a calculator that
First off, this isn't homework ;). I'm trying to create a wordsearch game from
I find myself oddly perplexed on this homework assignment. The idea is to create
I would like to ask for help. I got this homework to create a
I cannot figure this out. This is for homework. I need to create a

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.