Results 1 to 4 of 4
  1. #1
    blad90 is offline Member
    Join Date
    Aug 2015
    Posts
    3
    Rep Power
    0

    Default Checking if an array is zero inside Boolean class

    I don't know what I'm doing wrong.
    In this is a boolean function I want to that this takes some arguments as an ArrayList and returns whether it is a zero or not.

    Java Code:
    arg = [1, 3]
    
    public static boolean (ArrayList<Integer> arg){
    
    
            for(int i=0; i<arg.size(); i++){
    
    
                if (i == 0){
                   for(int s: arg){
    
           }
                    return true;
              }else{
                    return false;
    
                }
    
           }
        
        }
    
    }

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,422
    Blog Entries
    7
    Rep Power
    28

    Default Re: Checking if an array is zero inside Boolean class

    What do you mean? Should the method return true if all elements of the List are equal to zero? Just one of them? What if the List has zero length?

    kind regards,

    Jos
    Build a wall around Donald Trump; I'll pay for it.

  3. #3
    blad90 is offline Member
    Join Date
    Aug 2015
    Posts
    3
    Rep Power
    0

    Default Re: Checking if an array is zero inside Boolean class

    In a polynomial, If all elements contain a zero value, it should return zero. For example:

    f(x) = X + 2
    X=1
    f(1) = 1 + 2 = 3 (if is not equal to zero, it must return false)

    if X=(-2)
    f(-2) = (-2) + 2 = 0 (this should return true)

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,422
    Blog Entries
    7
    Rep Power
    28

    Default Re: Checking if an array is zero inside Boolean class

    So, if at least one of the elements isn't zero, your method is supposed to return false (that's the Morgan's law in disguise).

    kind regards,

    Jos
    Build a wall around Donald Trump; I'll pay for it.

Similar Threads

  1. 2D Boolean Array
    By JesusChrist in forum New To Java
    Replies: 8
    Last Post: 02-03-2014, 06:14 PM
  2. Replies: 6
    Last Post: 01-16-2014, 01:48 PM
  3. Checking if a Boolean Within Another Class Object is True
    By Alpharius120 in forum New To Java
    Replies: 5
    Last Post: 12-07-2012, 03:28 AM
  4. boolean isDigit() inside if statement
    By Googol in forum New To Java
    Replies: 2
    Last Post: 08-03-2012, 08:22 AM
  5. Replies: 1
    Last Post: 11-13-2011, 11:25 AM

Tags for this Thread

Posting Permissions

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