array substracting problem

Hi All,

I need some suggestion for making elements in the same array to subtract one another. For example, if the array is int a [ ] = {b,c,d}; , then I want the output to show the value of (c-b) ,(d-b), and (d-c). I actually wrote some lines but never get the right output(the output of this code is 49,69,79,30). Please point out the reason why it does not work out or suggest a better way. Thanks.

publicclass test{

publicstaticvoid main(String[] args){

int testA[]={1,50,70,80,100};

int testCounter=0;

int testCounterTwo=1;

while((testCounterTwo+testCounter)<testA.length&&testCounterTwo>testCounter){

int testEvaluator=testA [testCounterTwo+testCounter]-testA [testCounter];

System.out.println(testEvaluator);

testCounterTwo=testCounterTwo+1;

if ((testCounterTwo+testCounter)==testA.length-1){

testCounter=testCounter+1;

testCounterTwo=testCounter+1;

}

}

}

}

[1623 byte] By [kevinchanga] at [2007-11-27 8:45:54]
# 1

public class Substractamatron {

public static void main(String[] args) {

int[] data = {1,50,70,80,100};

for(int i=0; i < data.length-1; ++i) {

for(int j=i+1; j < data.length; ++j) {

System.out.format("%4d - %4d = %4d%n", data[j], data[i], data[j]-data[i]);

}

}

}

}

BigDaddyLoveHandlesa at 2007-7-12 20:47:26 > top of Java-index,Java Essentials,Java Programming...