1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Java prob.

  1. Aug 9, 2012 #1
    I have an array of 3 known elements.I know that 2 elements of them have the sum of 100 and I need to find the location of the two elements which have this sum
    ex.
    A[3]
    5 25 75
    the solution for this prob.
    is second & third location

    Thanks,
     
  2. jcsd
  3. Aug 9, 2012 #2

    rcgldr

    User Avatar
    Homework Helper

    In this case, there are only 3 possiblities, A[0] + A[1] or A[0] + A[2] or A[1] + A[2].

    For a more generic solution, you could use a double loop to handle an array with N elements. I don't know if this will be a later assignment for your homework.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Java prob.
  1. Animation in Java (Replies: 1)

  2. String in java (Replies: 7)

  3. Java program (Replies: 3)

  4. HeapSort Java (Replies: 3)

Loading...