Results 1 to 9 of 9

Thread: not compliling

  1. #1
    cjohnson412 is offline Member
    Join Date
    Nov 2008
    Posts
    3
    Rep Power
    0

    Default not compliling

    hI, i'm trying to have this method take in an array and have it look for anything over 8 hours in the array. I have an If else to look for any amount over 8. and to put into a new array...

    does anyone see any problem with this...
    Java Code:
    	public static int overTimeDetermin(int[] otArray)
    	{
    		int i=1,j=1;
    		int[] otCalcArray = new int[7]; 
    		
    		for(i=1; i<7; i++)
    		{
    			if(otArray[i]<8)
    			{
    				otCalcArray[i]=(otArray[i]-8);
    			}
    				else 
    			{
    				otCalcArray[i] = 0;
    			}	
    		}
    Last edited by cjohnson412; 11-24-2008 at 06:16 AM.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    what's going on here:
    Java Code:
    for(i=1; 1>8; i++)
    ?
    Arrays are 0 based so the first term should be i = 0;
    Your second term 1 > 8 makes no sense. One will never be greater than 8. usually here we try to make sure that i traverses the entire array, no more, no less, and so we use the array's own data to tell us when to stop: i < otCalcArray.length;

  3. #3
    racerxadam is offline Member
    Join Date
    Jul 2008
    Posts
    68
    Rep Power
    0

    Default

    i think you have a logic issue in your method. As it stands your if clause says, if the value of otArray[i] is less than 8, otCalcArray[i]=(otArray[i]-8) so you will be sticking negative numbers in the array. Additionally, do you plan on calculating an int value to return? if you intend to return the otCalcArray the method declaration will need to change.

    As always, if you are getting compile errors it is best to post the entire error message as that will make it easiest to diagnose the problem.

  4. #4
    emceenugget is offline Senior Member
    Join Date
    Sep 2008
    Posts
    564
    Rep Power
    7

    Default

    it's wise not to edit your original post, or if you do, note what you edited. someone who doesn't notice might think anyone commenting about what you edit out is crazy or stupid.

    anyways, what error do you get? do you know what it means? it'd be nice to see what you know and have tried.

  5. #5
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    I think you should care of arrays indexing. If you have forget those things, it's better to refer some materials about arrays as well. Because you are using index in wrong way.

    And also as emceenugget says, don't edit the original post. If you comes with something new post them in a new post.

    Once you get an error, please copy-paste the full error message to see others. It's really helpful to answering.

  6. #6
    dharmender378 is offline Member
    Join Date
    Nov 2008
    Posts
    16
    Rep Power
    0

    Default

    IF this is your whole message body then its not compiling as its not returning an int as expected.

  7. #7
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    8

    Default Undertime?

    I think the logic is wrong. If you're looking for overtime, shouldn't the if comparation be:
    Java Code:
    if(otArray[i]>8)
    Because otnerwise you'll be putting negatives numbers in array otCalcArray.

    Luck,
    CJSL
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

  8. #8
    cjohnson412 is offline Member
    Join Date
    Nov 2008
    Posts
    3
    Rep Power
    0

    Default

    wow, so as many of you may have noticed after I posted that i found a lot of little errors some people pointed out. Thanks for your help!

  9. #9
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    Actually lots of members are here ready to help you. Most important thing is you must explain the question more clearly :)

    If you have solve the problem please mark the thread as solved.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •