find the distance between two numbers(source and distination)in an array.the array size must be more than 5 and less than 10.

Recommended Answers

All 2 Replies

Find your code and post it here, then find the bit you are having problems with and ask about it here, then you will find people might want to help you...

idx1 = -1;
idx2 = -1;
for (int i=0; i<arr.length; i++) {
if (num1 == arr[i] && idx1 == -1) { idx1 = i;}
if (num2 == arr[i] && idx2 == -1) { idx2 = i;}
}

if (idx1 != -1 and idx2 != -1) { answer = Math.abs(idx2-idx1); }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.