Results 1 to 18 of 18
Like Tree2Likes
  • 1 Post By Rameshwar Soni
  • 1 Post By Tolls

Thread: an error in call array

  1. #1
    Join Date
    Jul 2011
    Posts
    47
    Rep Power
    0

    Default an error in call array

    i have a function and i want to call that but i got an error :
    this is my function and i want to call it :
    public boolean array220(int[] nums, int index) {
    ...........
    }
    ===================
    my main:
    public static void main (String argsp[]){
    vahid vhd = new vahid();
    vhd.array220({1,2,3}, 0);
    }

    i got this error : The method array220(int[], int) in the type vahid is not applicable for the arguments (int, int, int, int)

    what is wrong?

  2. #2
    Join Date
    Sep 2011
    Location
    Mumbai, India
    Posts
    35
    Rep Power
    0

    Default Re: an error in call array

    try this
    vhd.array220(new int[] {1,2,3},0);
    HearT.Hunt3r likes this.

  3. #3
    Join Date
    Jul 2011
    Posts
    47
    Rep Power
    0

    Default Re: an error in call array

    not worked

  4. #4
    Join Date
    Sep 2011
    Location
    Mumbai, India
    Posts
    35
    Rep Power
    0

    Default Re: an error in call array

    It should definitely work or there might be a possibility that you have some mistake in other part of the code.

  5. #5
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,846
    Rep Power
    19

    Default Re: an error in call array

    Java Code:
    public class Blah {
        public boolean array220(int[] nums, int index) {
            return true;
        }
    
        public static void main (String args[]){
            Blah b = new Blah();
            b.array220(new int[] {1,2,3}, 0);
        }
    }
    That compiles, as Rameshwar says...so if that doesn't work for you then you are doing something else wrong somewhere.
    HearT.Hunt3r likes this.

  6. #6
    Join Date
    Jul 2011
    Posts
    47
    Rep Power
    0

    Default Re: an error in call array

    Thx .. Fixed.

  7. #7
    Join Date
    Jul 2011
    Posts
    47
    Rep Power
    0

    Default Re: an error in call array

    my error fixed but it didn't work! my array is : {1,2,3} when i write System.out.println(nums) it say: [I@2e6e1408

  8. #8
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,846
    Rep Power
    19

    Default Re: an error in call array

    Which is correct.
    It's an array of integers ([I) at that address.
    Basic arrays do not have a toString() of their own, so they default to that of Object, which prints out the classname and the address (generally).

    There is a toString method() in the Arrays utility class you could use.

  9. #9
    Join Date
    Jul 2011
    Posts
    47
    Rep Power
    0

    Default Re: an error in call array

    i confused! i just wanna see my output and i can't ... what can i do?
    My Main :
    public class Apples {


    public static void main (String argsp[]){

    vahid vhd = new vahid();
    vhd.array220(new int[] {20,2,21}, 0);

    }
    }

    My Function:
    public class vahid{
    public boolean array220(int nums[], int index) {
    if(index==nums.length){
    return false;
    }else if(index+1<nums.length && nums[index+1]==0){
    return array220(nums,index+1);
    }else if(index+1<nums.length && nums[index+1]/nums[index]==10){
    return true;
    }else{
    return array220(nums,index+1);
    }
    }
    }

  10. #10
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default Re: an error in call array

    i just wanna see my output and i can't ... what can i do?
    Where do you have a print statement to show your output?
    Where do you want to see your output?

    What is the output you want to see?
    The array220 method returns a boolean. Do you want to see true or false?
    Then save what is returned by the method and print it.

  11. #11
    Join Date
    Jul 2011
    Posts
    47
    Rep Power
    0

    Default Re: an error in call array

    in debug mode

  12. #12
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default Re: an error in call array

    Sorry, I don't know anything about your IDE.
    You can use printlns to show the values of variables on the console.

  13. #13
    Join Date
    Jul 2011
    Posts
    47
    Rep Power
    0

    Default Re: an error in call array

    this is question :
    Given an array of ints, compute recursively if the array contains somewhere a value followed in the array by that value times 10. We'll use the convention of considering only the part of the array that begins at the given index. In this way, a recursive call can pass index+1 to move down the array. The initial call will pass in index as 0.
    and this is examples:
    array220({1, 2, 20}, 0) → true
    array220({3, 30}, 0) → true
    array220({3}, 0) → false

  14. #14
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default Re: an error in call array

    I'm not sure what the reason is for your last post.
    Do you have a question or a problem?

  15. #15
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,846
    Rep Power
    19

    Default Re: an error in call array

    OK.
    So you want to print out true or false?
    So print out the returned value from array220.

  16. #16
    Join Date
    Jul 2011
    Posts
    47
    Rep Power
    0

    Default Re: an error in call array


    my input is empty... i donnu how i should say my problem :(

  17. #17
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,846
    Rep Power
    19

    Default Re: an error in call array

    Are you calling the program with any parameters?

  18. #18
    Join Date
    Jul 2011
    Posts
    47
    Rep Power
    0

    Default Re: an error in call array

    public class Apples {


    public static void main (String argsp[]){

    vahid vhd = new vahid();
    vhd.array220(new int[] {20,2,21}, 0);

    }
    }

Similar Threads

  1. Replies: 3
    Last Post: 08-16-2011, 07:57 PM
  2. Function call returning array of objects
    By ShitalJain in forum New To Java
    Replies: 4
    Last Post: 06-25-2011, 09:39 AM
  3. Replies: 1
    Last Post: 03-17-2010, 05:25 AM
  4. function call error
    By peter_thm in forum New To Java
    Replies: 2
    Last Post: 01-13-2010, 12:57 PM
  5. Replies: 0
    Last Post: 07-07-2008, 07:10 AM

Posting Permissions

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