How do you count the position in an array?

Label the elements in a 2D array by counting left to right across each row, and starting with the top row, working your way down. For the example above, we'd label each element like so:
0 1 2 3
4 5 6 7
8 9 10 11
12 13 14 15
16 17 18 19
Such labels give the position in the linearized array (so called because we can store them in a one-dimensional array now). (We did this secretely when we constructed deck out of suit and rank. Check out pages 91�92 if you need to refresh your memory.)
Come up with a way to calculate the row of an element in the two-dimensional array given its linearized position. For example, the row of element 6 is 1. Also devise a way to calculate the column of a element in the two-dimensional array given its position in the linearized array. For example, the column of element 6 is 2. (Remember, we start counting at zero.) Explain how you arrived at your answer.
There is no code needed for this, and my question is how should I start this? I am not sure how to track down a value in a two dimensional array... can anyone help?

Java arrays can be "ragged". Assuming the outer array represents rows and the inner array represents columns, the inner arrays that define the columns can be of different length. In your example you could have
0 1 2
3 4 5 6 7 8
9 10 11 12 13 14
15
16 17 18 19
So. unless you can specify that the column arrays will all be the same size, you'll have to have some way of determining the array size before it can be use in any calculation. You will find <anArray>length useful.

Similar Messages

  • How do you change the position of email sender so that it's on the left (sender[from], subject and date received)

    How do you change the position of email sender so that it's on the left (sender[from], subject and date received)

    In the Thread Pane where your messages are listed?
    You see that bar with the labels "From", "Subject", "Date" and so on? Well, they are buttons. You can click on them to sort your messages. You can also drag them with the mouse left and right to reposition them, and you can drag their ends to change the column widths.
    These are standard computer actions; you can do all of this in Windows Explorer ("My Computer") too.
    In Thunderbird, a right-click on any of these buttons will reveal a pop-up menu where you can select and deselect the columns to control what is shown.
    More here: http://www.ramsden.org.uk/8_How_to_sort.html

  • How do you count the multiple columns of a field in a table

    How do you count the multiple columns of a field in a table

    Hi,
    4396bf34-e890-4202-a6b0-4e08c9ff0e89 wrote:
    How do you count the multiple columns of a field in a table
    Whenever you have a problem, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all tables involved, and also post the results you want from that data.
    Explain, using specific examples, how you get those results from that data.
    Always say which version of Oracle you're using (e.g., 11.2.0.2.0).
    See the forum FAQ: https://forums.oracle.com/message/9362002
    "Field" isn't a standard database term.  Some people say "field" when they mean "column", but I don't think that's what you mean ("How do you count the multiple columns of a column ..").  Do you want to know how many times a column is used (as opposed to NULL), or the number of different values in a column?  You really need to show what you want.

  • How do you get the average of an array bigdecimels

    how do you get the average of an array bigdecimels... I am looping through the array in a for loop
    for (int i = 0; i < prItems.length; i++) {                                                                                                                                                                                                                                                                                                                  

    int sum = 0;
    for (int i = 0; i < prItems.length; i++) {
    sum = sum + prItems;
    int avg = sum/prItems.length;

  • How do you fix the position of an object vertically only ("static" position horizontally)?

    I want to fix a "title" bar of a table vertically, but allow it to scroll with the rest of the page content horizontally. At the moment it's position is "fixed" which fixes the position vertically but horizontally too. I would like to have the coloured cells move horizontally with the rest of the table in the case that the browser window is not wide enough.
    Can this be done? If so, how?
    (this picture shows that the horizontal positions are different - would like them to remain in line with each other)
    Sorry if this is a silly question, I've only started using Dreamweaver yesterday... Thank you in advance for any help and advice.

    If you want to align your item horizontally center, left or right (along with other website content), you can put that item within a fixed position container, then align the item within the container however you see fit.
    <html>
    <head>
    <title></title>
    </head>
    <body>
    <div id="container" style="position:fixed; top:0px; height:100px; width:100%; border:1px solid orange;">
         <div id="item" style="width:300px; margin:auto; border:1px solid black">Some Content</div>
    </div>
    </body>
    </html>
    In the simplified example above, the container div is fixed to the top of the page, the item div is also then fixed at the top, however using css, it is  centered to the browser window. The border properties are there for illustrative purposes

  • How do you set the position of JScrollBars?

    Can anyone tell me how to set the positions of the JScrollBars in a JScrollPane so that it will show the area I want?
    please,
    Tommy

    Sorry i should of add the area I am talking about is a JPanel.

  • How do you count the amount of times a button is clicked?

    Heres my code:
    public void buttonClicked(JButton buttonzilla){
    if(buttonzilla == startButton){
    while(i < 7){
    story.append("\n" + "\n" + abc);
    i++;
    However, when i click the button once, it displays all elements in the array, however, im trying to get it so that each time i click the button another element is displayed, one at a time. How would i go about doing this?

    Can you explain the code because it dosent make sense
    to me, im a beginner.In the code you posted, there is no declaration for the variable i, so I've assumed it is declared as a class variable, and has scope within the class.
    You say you want to add only the data from the element of abc[], relative to the number of times the button has been clicked i.e. 1st click adds abc[0], 2nd click adds abc[1] etc.
    if(i < abc.length)  - to ensure no ArrayIndexOutOfBoundsException (really should also check i is not negative)
    story.append("\n" + "\n" + abc[i++]);
    instead of
    story.append("\n" + "\n" + abc);
    i++;

  • How do you get the position of keyboard on the JTextComponent

    hi, i would like to do copy and paste
    and what i would like to know say
    i got text "Hello" if i place my keyboard between "H' and "e", i would like the computer to tell me the position of my keyboard!
    can anyone plz help ?
    Thx in advance!
    Sam

    Keyboard == cursor?
    int pos = jTextComponent.getCaretPosition();getCaretPosition
    public int getCaretPosition()
    Returns the position of the text insertion caret for the text component.
    Returns:
    the position of the text insertion caret for the text component >= 0

  • How do you count the number of unique values?

    I wanted to know how to create a function that will tell me how many unique values are in a list of values.
    For example if I had this list:
    15
    15
    12
    12
    12
    2
    1
    I would get a result of 4. Because there are only 4 unique values 15, 12, 2, and 1.
    I'm trying to create a spreadsheet that modeled the Sainte-Laguë method of voting; in case you're wondering. I'm using Numbers '09 if it matters.
    Thanks

    Thanks for the responses. That was fast.
    I was hoping to fit it all in one cell, but I guess I could hide the columns used for calculation. I tried Badunit's Function and it works. However I found that if I have a column of all the same number it will return 0, when in fact it should return 1. Like if I had a column of 14s I should get one, because the number of different values that appears is 1. Also a minor note is that COUNTIF(B$2:B2,B2) should be COUNTIF(B2:B$2,B2), that makes sure that if you have anything below it doesn't interfere. At least that's what made it work for me.
    Well I looked at the way you did your chart, Badunit, and it makes more sense than the way I was doing it. I was having to manually enter the number of seats every new row. I think it would have been easier to write a java program.
    Anyways you guys have been helpful. Thanks again.

  • How do you control the position and size of images, i.e,. photo to the printer?

    HP Officejet 8600
    Windows XP
    I am trying to figure out how to control the positon and size of photos or pics that are included in an email that I send to my printer via HP ePrint.
    This question was solved.
    View Solution.

    Hey Old_Salt,
    What model HP printer do you have?
    ePrint is a very simple system when it comes to printing, because it doesn't provide as many controls as one may be used to with a computer.  Many of the photosmart printers are designed to recognize a photo in ePrint and print the image to the proper photo paper.
    Jason
    -------------How do I give Kudos? | How do I mark a post as Solved? --------------------------------------------------------
    I am not an HP employee.

  • How do you count the frequency of a boolean signal?

    Hi, I'm new to LabVIEW, so I suspect this is propbably quite a simple problem.
    I'm developing an optical tacometer for a model gas turbine engine. I have a boolean signal in labview which is switching at a frequency between 4 and 26Hz. I need a live readout of the frequency of this signal.
    Does anyone know how I could do this? Any help would be really appreciated!
    Many thanks
    Will
    Solved!
    Go to Solution.

    This vi should work for you
    Tim
    Johnson Controls
    Holland Michigan
    Attachments:
    Calculate Frequency from boolean.vi ‏11 KB

  • How do you count the frequency of a booloen signal?

    Hi, I'm new to LabVIEW, so I suspect this is propbably quite a simple problem.
    I'm developing an optical tacometer for a model gas turbine engine. I have a boolean signal in labview switching between 4 and 26Hz. I need a live readout of the frequency of this signal.
    Does anyone know how I could do this? Any help would be really appreciated!
    Many thanks
    Will

    New post here...
    http://forums.ni.com/ni/board/message?board.id=170​&message.id=481337
    Rich R
    Applications Engineer
    National Instruments UK & Ireland

  • How do you change the ViewPlatform

    How do you change the position and angle of the ViewPlatform.
    There doesnt seem to be anything about this in the J3D tutorial or in the documentation.
    Please help.

    oops, close but no bannana, simpleU.getViewingPlatform() and simpleU.getViewPlatformTransform(). then alter as i mentioned above. (assuming you're using SimpleUniverse that is, if you're not, then its easy).

  • How do you modify the default Execute thread count in Weblogic Server 9.2?

    How do you modify the default Execute thread count in Weblogic Server 9.2?
    How can you tune the starting number of weblogic.ExecuteThread on server startup and/or set minimum number?
    Is there an option from the console?
    Please let me know.
    Thanks

    Self tuning will automatically manage the threads but however you can still control the min and max by adding the min and max values for each instance either directly adding in config.xml or through JVM settings
    1) Modifying the config.xml
    Just add the following line(s) to each server definition :
    <server>
    <name>AdminServer</name>
    <self-tuning-thread-pool-size-min>100</self-tuning-thread-pool-size-min>
    <self-tuning-thread-pool-size-max>200</self-tuning-thread-pool-size-max>
    </server>
    2) Adding some JVM parameters
    It's safer the following way :
    add the following option in your command line : -Dweblogic.threadpool.MinPoolSize=100
    Regards
    RR

  • How do you get  the count of number of  checkbox selected?

    hi,
    plz tell me how do you get the count of number of checkbox selected?

    Not sure what you are doing so I will attempt to answer your question. If have one question which can have multiple answers you have will recieve an array so you have to do getParameterValues("name") and move it into an array.
    If you have multiple questions and only value will be selected do a getParameter("name") on each form element.
    HTH, if not provide more detail.
    J.Clancey

Maybe you are looking for

  • Rec guitar in logic 8

    Hi there............ how can i connect my guitar * gibson les p.)in logic 8, and rec it ? do i need a specific item ? thanks ,,,, see ya

  • SAP PS budget release problem

    We are following MTO scenario and we are releasing SAP Project with save of Sales Order. Later we are assigning(CJ30) and releasing(CJ32) budget in SAP Project, with budget release System status "NBUD" replaced with System status "BUD". But, some tim

  • How do I update my mac to 10.6.8?

    how do I update my mac to 10.6.8?

  • Ipod break down wireless lan

    Hello everybody, i have a problem with my new iPod touch 4. I have a wireless network with 2 laptops and want to integrate my iPod. When I activate the wireless lan of my iPod and my laptop is on the net, everything is ok. If my laptop isn't on the n

  • PGP - XI 3.0

    Hi All, I am currently working on a scenario where secure data from ECC needs to be sent to one of the third party via XI and Seeburger. The flow would be : SAP ECC -> XI 3.0 -> Seeburger -> Target system A encrypted txt file using PGP needs to be se