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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T09:23:33+00:00 2026-06-06T09:23:33+00:00

Problem Statement is : Given 2 Dimensional array, print output for example If 4

  • 0

Problem Statement is :

Given 2 Dimensional array, print output for example

If 4 rows and 6 columns, output would be:

        1    2    3    4    5    6 
        16   17   18   19   20   7
        15   24   23   22   21   8
        14   13   12   11   10   9

I tried it is looking like square within square but when I attempted this problem, I put so many while and if loops but didn’t got exact answer. If row and columns increases how to handle it?

This is not homework. I was learning solving complex structure so I need to understand it by some guidance.

  • 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-06T09:23:34+00:00Added an answer on June 6, 2026 at 9:23 am

    Here is what I came with.

    Variables name may be upside/down, lot of thing to enhance, remove, modify but it was fun game.

    public class Test {
        public static void main(String[] args) {
            int x = 2;
            int y = 2;
            int idx = 1;
            int[][] array = new int[x][y];
            int yUpIdx = y-1;
            int yDownIdx = 0;
            int xLeftIdx = 0;
            int xRightIdx = x-1;
    
    
            while (idx < x*y) {
                for (int i = xLeftIdx; idx <= x*y && i <= xRightIdx; i++) {
                    array[i][yDownIdx] = idx++;
                }
                yDownIdx++;
                for (int j = yDownIdx; idx <= x*y &&  j <= yUpIdx; j++) {
                    array[xRightIdx][j] = idx++;
                }
                xRightIdx--;
                for (int i = xRightIdx; idx <= x*y &&  i>=xLeftIdx ; i--) {
                    array[i][yUpIdx] = idx++;
                }
                yUpIdx--;
                for (int j = yUpIdx; idx <= x*y &&  j>=yDownIdx ; j--) {
                    array[xLeftIdx][j] = idx++;
                }
                xLeftIdx++;
            }
            for (int j = 0; j < y; j++) {
                for (int i = 0 ; i < x; i++) {
                    if ((array[i][j]+"").length() < 2) System.out.print(" "); 
                    System.out.print(array[i][j]+" ");
                }
                System.out.println("");
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Problem Statement is somewhat like this: Given a website, we have to classify it
Problem Statement: Given an array of ints, compute if the array contains somewhere a
This is a spin-off of one of my earlier questions Problem statement: Given a
UPDATE:: OK i am putting the original problem statement here Given the Main class
Problem statement: For a given positive number, I have to find out the immediately
Below is the Problem Statement: PS: Given a string and a non-empty substring sub,
I have the below Problem Statement PS: Given a string str and a Non-Empty
Im stuck with the below problem. Problem Statement: Given a non-negative int n, return
I have a stored Procedure (Generate_Insert)which will output an Insert statement as output given
Problem statement: You are given a set of k strings, each length n. You

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.