Results 1 to 2 of 2
  1. #1
    Domenatrice is offline Member
    Join Date
    Nov 2011
    Posts
    4
    Rep Power
    0

    Default Checking if a value only apears once in an array

    I am writing a program that solves sudoku and I need to make sure my array only contains the values one through ten and I also need to add them all up to make sure they equal 45.

    Thanks!

  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,585
    Rep Power
    12

    Default Re: Checking if a value only apears once in an array

    You can check that an array contains no duplicates by making a Set out of it and checking it's size. Or you can use for loops and check that no entry in the array is followed by an entry with the same value.

    You can constrain the values in an array by simply never adding any value that you consider illegal. After the fact, the for loop mentioned above can also check that each value is good. A for loop can also keep track of the total.

Similar Threads

  1. Replies: 1
    Last Post: 11-13-2011, 12:25 PM
  2. checking array items are equal
    By trishtren in forum New To Java
    Replies: 5
    Last Post: 10-16-2011, 01:23 PM
  3. Checking to see if Array is sorted
    By pytho in forum New To Java
    Replies: 5
    Last Post: 07-06-2011, 02:39 AM
  4. Checking ascending order of array
    By counterfox in forum New To Java
    Replies: 3
    Last Post: 10-22-2010, 11:44 PM
  5. Replies: 5
    Last Post: 03-19-2010, 01:26 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
  •