Can somebody shine light on this Array problem I've got

This is the error message I get when I run my code, I've looked at the array but can't see the problem.
java.lang.ArrayIndexOutOfBoundsException
     at Test.main(Test.java:18)
Exception in thread "main"
I've set code below.
Dave
import corejava.Console;
public class Test{
public static void main (String[] args){
int total = 0;
int MealsInfo;
int Week = 0;
int Day = 0;
int Meals[][] = new int[2][5];//2 columns 5 rows
for(Week = 0; Week <2; Week ++){
for(Day = 0; Day <5; Day ++){
MealsInfo = Console.readInt("Please insert number of Meals" );
Meals[Week][Day] = MealsInfo;
total = Meals[Week][Day];
System.out.println(Meals[Week][Day]);
}

FriedrichHoffmann in right.
The ArrayIndexOutOfBounds Exception comes from the fact that after you exit a for loop the condition in the middle part of the for statement is false, so in the case of your for loops week == 2 and day == 5 when the for loops finish executing.
As arrays are zero indexed (as you should already know) the last line should be
System.out.println(Meals[Week-1][Day-1]);But this will only print out the last element in the array, what you want is to have the System.out call inside the second (nested) for loop.
Hope this helps.

Similar Messages

  • I have a project that crashed on me when I was about to finish it. When I try to reopen Final Cut Pro it wouldn't open until I took the project out of the Final Cut Project folder. Can somebody tell me if this is a problem that has a solution? I cannot

    I have a project that crashed on me when I was about to finish it. When I try to reopen Final Cut Pro it wouldn't open until I took the project out of the Final Cut Project folder. Can somebody tell me if this is a problem that has a solution? I cannot go back to the project at all.

    If you are using 10.0.3 or above Apple added a backups folder that for a little extra protection in cases like this. If you quite FCPX go to your Final Cut Pro Projects folder. Find the folder that has the project in question. If it has a backups folder there should be a file with a date stamp and .fcpproject extention, that is your back-up. Just move the back-up from that folder one folder up to the place where you deleted CurrentVersion.fcpproject from.  When I have had to do this I haven't renamed the backup but some people to recomend that you rename it to CurrentVersion.fcpproject and it seems to work both ways. Ofcourse it wont work if there is already a CurrenVersion file there you will need to delete that one first.
    If you don't have the backups folder or there is nothing in it I am not sure if there is anything that can be done.

  • We used to get a 'whooshing' noise when we sent an eMail using mac Mail. This no longer happens. We recently updated to Mountain Lion 10.8.1  Can anyone throw light  on this please?    David

    We used to get a 'whooshing' noise when we sent an eMail using mac Mail. This no longer happens. We recently updated to Mountain Lion 10.8.1  Can anyone throw light  on this please?    David

    Hi
    I am sorry to see you are having problems with your BT Service
    I suggest you contact the forum mods they should be able to get this problem sorted for you this is a link to them http://bt.custhelp.com/app/contact_email/c/4951
    They normally reply by email or phone directly to you within 3 working days they will take personal ownership of your problem until resolved and will keep you informed of progress
    They are a UK based BT specialist team who have a good record at getting problems solved
    This is a customer to customer self help forum the only BT presence here are the forum moderators
    If you want to say thanks for a helpful answer,please click on the Ratings star on the left-hand side If the reply answers your question then please mark as ’Mark as Accepted Solution’

  • Can somebody please confirm/deny this?

    Can somebody please confirm/deny this?
    FP 9 on Linux shows time one hour ahead than the local time.
    Try following line with FP9 on Linux
    trace("Current Time "+new Date());

    On Thu, 11 May 2006 05:35:14 -0400, Nikolay <[email protected]>
    wrote:
    > I think the files in
    > http://download.eclipse.org/webtools/downloads/drops/R-1.0.2 -200604200208/
    > are wrong! Can somebody please confirm/deny this?
    >
    Yes, they are "out of date", even though code is the same. The 1.0.2
    release was refreshed, the code plugins are all exactly the same, but the
    qualifier on some features (and, hence, code plugins) were
    fixed up to allow update manager to work. The correct "drop site" for
    1.0.2 is now
    http://download.eclipse.org/webtools/downloads/drops/R-1.0.2 -200604280245/
    I think, actually, the problem with the update site is that update manager
    has a tendancy to give you only the "smallest" most recent update. If you
    would have said "update again", even using the mirror, I believe it would
    have given you another update, the 1.0.2.v200604280000 version.
    If I can figure out a safe way to do it, some day I'll clean out those
    "out dated" versions (200604200208) to help avoid the confusion. But, as a
    general rule, when ever you use update, you might want to do it several
    times, until it tells you "there are no updates". If you are in the mood
    to experiment to confirm this, that would be great (although, obviously,
    you'd have to "start over" with your prevous version, and I do not know
    how easy that would be for you.)
    Thanks,

  • The Apple instructions with no luck. Grateful if anyone can shed some light on this !

    I seem to be unable to locate or play iTunes Radio in iTunes. I have followed the Apple instructoins with no luck. Grateful if anyone can shed some light on this !

    Thanks very much. Now I feel stupid!!

  • I have a galaxy S4. When I connect a headphone, certain songs play extemely low while others play at the correct volume. The same songs play fine thru the speakers. Can someone shed light on this.

    I have a galaxy S4. When I connect a headphone, certain songs play extremely low while others play at the correct volume. The same songs play fine thru the speakers. Can someone shed light on this.

        chrisglobe7,
    We want you to be able to enjoy all your music! Were all the songs downloaded from the same source? Are all the songs that play at the low volume from the same place? Is the music you are listening to stored on your device or a 3rd party application?
    LindseyT_VZW
    Follow us on Twitter @VZWSupport

  • How do tune sql query? Can somebody help me in this? Atleast prescribe book

    how do tune sql query? Can somebody help me in this? Atleast prescribe a reference book.
    I am not able understand How to analyze tkproof output.

    Check out asktom.oracle.com
    Lot's of threads on interpreting tkprof output - no simple easy solution here.
    You need to understand what is happening and THINK. Then you can be a good engineer.
    As for good books...
    Tom Kyte's books are really, really good.
    http://www.amazon.com/Effective-Oracle-Design-Osborne-ORACLE/dp/0072230657/ref=sr_1_3?ie=UTF8&s=books&qid=1266783471&sr=8-3
    http://www.amazon.com/Expert-Oracle-Database-Architecture-Programming/dp/1590595300/ref=sr_1_1?ie=UTF8&s=books&qid=1266783471&sr=8-1
    Good luck!

  • Since I upgraded to iOS 7.0.4 on my iPad 3, battery capacity has drained almost 10%/hour without any use of the device. Prior to the upgrade, the battery charge would hold during periods of inactivity. What can I do to solve this significant problem?

    Since I upgraded to iOS 7.0.4 on my iPad 3, my battery capacity has drained almost 10% per hour without any use of the device. Prior to the upgrade, the battery charge would hold during periods of inactivity. What can I do to solve this significant problem? Is there a way to uninstall iOS 7.0.4 and return to the previous version?

    Downgrading isn't supported.
    You can poke around in the settings. There's a lot of stuff defaulted to on that you may not need, such as notifications.
    You can also look into background app refresh and background app updates. They can be running in the background and drain your battery.

  • In Mail, one mailbox for Recovered Message (AOL) keeps showing 1 very large message that I cannot delete. How can I get rid of this recurring problem, please?

    In Mail on iMac, successfully running OS X Lion, one mailbox on My Mac for "Recovered Messages (from AOL)" keeps showing 1 very large message (more than 20 Mb) that I just cannot seem to delete. Each time I go into my In Box, the "loading" symbol spins and the message appears in the "Recovered Messages" mailbox. How can I get rid of this recurrent file, please?
    At the same time, I'm not receviving any new mails in my In Box, although, if I look at the same account on my MacBook Pro, I can indeed see the incoming mails (but on that machine I do not have the "recovery" problem).
    The help of a clear-thinking Apple fan would be greatly appreciated.
    Many thanks.
    From Ian in Paris, France

    Ian
    I worked it out.
    Unhide your hidden files ( I used a widget from http://www.apple.com/downloads/dashboard/developer/hiddenfiles.html)
    Go to your HD.
    Go to Users.
    Go to your House (home)
    there should be a hidden Library folder there (it will be transparent)
    Go to Mail in this folder
    The next folder ( for me ) is V2
    Click on that and the next one will be a whole list of your mail servers, and one folder called Mailboxes
    Click on that and there should be a folder called recovered messages (server) . mbox
    Click on that there a random numbered/lettered folder -> data
    In that data folder is a list of random numbered folders (i.e a folder called 2, one called 9 etc) and in EACH of these, another numbered folder, and then a folder called messages.
    In the messages folder delete all of the ebmx (I think that's what they were from memory, sorry I forgot as I already deleted my trash after my golden moment).
    This was GOLDEN for me. Reason being, when I went to delete my "recovered file" in mail, it would give me an error message " cannot delete 2500 files". I knew it was only 1 file so this was weird. Why 2500 files? Because if you click on the ebmx files like I did, hey presto, it turned out that they were ALL THE SAME MESSAGE = 2500 times. In each of those folders in the random numbers, in their related message folder.
    Now remember - DONT delete the folder, make sure you have gone to the message folder, found all those pesky ebmx files and deleted THOSE, not the folder.
    It worked for me. No restarting or anything. And recovered file. GONE.
    Started receiving and syncing mail again. Woohoo.
    Best wishes.

  • Can somebody help me with this code?

    Can anyone help me with this code? My problem is that i can't
    seem to position this form, i want to be able to center it
    vertically & horizontally in a div either using CSS or any
    other means.
    <div id="searchbar"><!--Search Bar -->
    <div id="searchcart">
    <div class="serchcartcont">
    <form action='
    http://www.romancart.com/search.asp'
    name="engine" target=searchwin id="engine">
    <input type=hidden value=????? name=storeid>
    <input type=text value='' name=searchterm>
    <input type=submit value='Go'> </form>
    </div>
    </div>
    <div class="searchcont">Search For
    Products:</div>
    </div><!-- End Search Bar -->
    Pleasssssseeeeeeee Help
    Thanks

    Hi,
    Your form is defined in a div named "serchcartcont", you can
    use attributes like position and align of the div to do what you
    want to do. But there are two more dives above this dive, you will
    have define the height width of these before you can center align
    the inner most div. If you are not defining the height & width
    then by default it decide it automatically to just fit the content
    in it.
    Hope this helps.
    Maneet
    LeXolution IT Services
    Web Development
    Company

  • Can somebody please simplify/tune this query?

    Hi,
    Can somebody please simplify this query?
    It's a little urgent. Currently this query is taking 10 mins to run.
    Thank you so much,
    vasu
    Purpose:
    First Child Case Ind =
    Get Parent Case for this case.
    Get all child cases for this parent case.
    Arrange them in ascending order by create Date.
    If the first case (eldest case) is the case in question,
    then Y
    else N
    Query:
    SELECT THIS_CASE.OBJID THIS_CASE_OBJID,
    PARENT.PARENT_OBJID,
    (CASE
    WHEN PARENT.FIRST_CHILD_OBJID = THIS_CASE.OBJID
    THEN 'Y'
    ELSE 'N'
    END) IS_FIRST_CHILD_CASE
    FROM SA.TABLE_CASE THIS_CASE,
    (SELECT PARENT_OBJID,
    CHILD_OBJID FIRST_CHILD_OBJID
    FROM (SELECT PARENT_CASE.OBJID PARENT_OBJID,
    CHILD_CASE.OBJID CHILD_OBJID,
    CHILD_CASE.CREATION_TIME,
    ROW_NUMBER() OVER (PARTITION BY PARENT_CASE.OBJID
    ORDER BY CHILD_CASE.CREATION_TIME ASC) ROW_NUM
    FROM SA.TABLE_CASE PARENT_CASE,
    SA.TABLE_CASE CHILD_CASE
    WHERE PARENT_CASE.OBJID = CHILD_CASE.CASE_VICTIM2CASE
    WHERE ROW_NUM = 1
    ) PARENT
    WHERE THIS_CASE.CASE_VICTIM2CASE = PARENT.PARENT_OBJID(+)

    Thank you for the quick reply.
    Here is the explain plan:
    Operation     Object Name     Rows     Bytes     Cost
    SELECT STATEMENT Optimizer Mode=CHOOSE          2 M          32831
    HASH JOIN OUTER          2 M     130 M     32831
    TABLE ACCESS FULL     SA.TABLE_CASE     2 M     24 M     21550
    VIEW          307 K     11 M     10130
    WINDOW SORT PUSHED RANK          307 K     7 M     10130
    MERGE JOIN          307 K     7 M     8666
    TABLE ACCESS BY INDEX ROWID     SA.TABLE_CASE     307 K     4 M     1266
    INDEX FULL SCAN     SA.IND_CASE_VICTIM2CASE     307 K          738
    SORT JOIN          2 M     19 M     7400
    INDEX FAST FULL SCAN     SA.PK_TABLE_CASE     2 M     19 M     785
    Please let me know.
    Thank you.

  • Annoying volume display, can somebody do something about this?

    I have been an iphone/ipad user forever but somehow I feel that lately this has been bugging me a lot. Can somebody please do something about this feature, wherein that huge volume display takes over whatever you are watching everytime you adjust the volume on the iphone and the ipad?
    Does this bother others too or is it just me?

    As mentioned, this is a user to user forum.  If you don't like this feature (or anything else about iPhone for that matter), feel free to provide feedback directly to Apple via the following link:  https://www.apple.com/support/contact/

  • Please can somebody tell which network this iPhone 5 is locked to?

    Serial Number: C38JHVP6F39C
    Part Description: IPHONE 5 64GB BLACK
    Product Version: 6.1.4
    Coverage Status: Apple Limited Warranty
    Coverage End Date: 29/10/13
    First Unbrick Date: 30/10/12
    Last Unbrick Date: 04/07/13
    Next Tether Activation Policy Description: UK O2 Tesco.
    Lock Status: Locked
    Please can somebody tell me which network this iPhone 5 is locked to?

    Call AppleCare and ask them. No one but Apple has access to that information.

  • Hi, I am from Maldives can anyone pls help me this sms problem.. I restored many times but sms not delivered.. pls help me????

    about one month this problem but I can't solve...

    Are you using a supported carrier? SMS is a carrier feature. Talk to them about it.

  • Can somebody please explain me this logic?

    array = [1,2,3,4,5,6,7];
    newArray = array;
    trace ("array: " + array);
    newArray = newArray.splice (0, 5);
    trace ("array: " + array);
    Output:
    array: 1,2,3,4,5,6,7
    array: 6,7
    As you can see, I set a variable equal to another (newArray = array), then splice it. But the problem is, it is affecting the old variable too!
    How can that be?
    I need to use the complete original "array", but no matter how many variables I create equal to it, when I splice them, it affects all of them!
    I might find a solution by turning the variable into string, then back to array or something like that. But what I would like is to understand what's going on in that code. If someone could explain me, i'd appreciate it a lot.

    Thank you.
    That helped me out.
    I found my problem also in the Flash Documentation. I couldn't find it before because i didn't know what to look for.
    Anyway, here's the link if someone wants it:
    http://livedocs.adobe.com/flash/9.0/main/wwhelp/wwhimpl/common/html/wwhelp.htm?context=Liv eDocs_Parts&file=00000661.html
    It teaches how to create a copy of an array using a "for", but "kglad's" method is much better.

Maybe you are looking for