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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T02:35:38+00:00 2026-06-19T02:35:38+00:00

Don’t understand how to solve this. I need to accept a seat number as

  • 0

Don’t understand how to solve this.
I need to accept a seat number as a parameter (seat). And then convert that seat number into a row and column index for the two-dimensional array.

to check myself I’ve been assuming there are 10 rows (0-9) and 2 seatsPerRow (0-1) and picking a seat from 1-20 out of that to check the math. BUT There can be any amount of rows and columns. This is just what I’m using to check myself.

static void isAvailable(int seat, boolean seat[][]) {

    int row = 0;
    int column = 0;

    if (seat > 0 && seat <= (getRows() * getSeatsPerRow())){
        row = (seat ) % getRows();
        column = (seat - 1) % getSeatsPerRow;
        seat[row][column] = false;
    }
}

Assuming the seats were arranged this way:

            seatsPerRow
       0   1   2   3   4   5   6 

    0 (1) (2) (3) (4) (5) (6) (7)

 r  1 (8) (9) (10)(11)(12)(13)(14)

 o  2 (15)(16)(17)(18)(19)(20)(21)

 w  3  ...

 s  4  ...

    .

    .

    .

Say I wanted to find seat 11. It would be seat[1][3]. I don’t understand how to convert the seat number to the location on the 2-d array.

  • 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-19T02:35:39+00:00Added an answer on June 19, 2026 at 2:35 am

    Well, assuming seats are numbered starting at 1, you can get the column index simply by using:

    int column = (seatNum - 1) % seat[0].length;
    

    You can then find the row with a simple expression:

    int row = (int) ((seatNum - 1) / seat[0].length);
    

    Then, you’d get the actual element by doing:

    seats[row][column]
    

    Both these expressions should work for all dimensions of the seat array (except 0 x 0).

    The first line will use modulo to find the remainder of seatNum / seat[0].length, or basically the seat number divided by the number of seats per row. This will restruct column to the correct range.

    Next, the second line will divide the number of seats by the length of a row, which will find the row itself. We then cast it to an int with (int), which truncates it, dropping any decimal that may have resulted from the operation. In this case, we’re actually performing purely integer math, so the cast is unnecessary.

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

Sidebar

Related Questions

Don't think that I'm mad, I understand how php works! That being said. I
Don't understand this simple code: def main(): print (This program illustrates a chaotic function)
Don't understand, if Data.Map is and [] is. I found this out while wondering
Don't ask me why but i can't use this method because I need to
Don't need to do this right now but thinking about the future... What would
Don't know if there is a better way to do this, so that is
Don't quite understand why this copy constructor is not invoked when I build with
Don't dismiss this as a newbie question! It's not, I'm not, I've tried everything,
Don't ask me why but I need to do the following: string ClassName =
I don't know why, but this code worked for me a month ago... maybe

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.