-1

I have two arrays;

 int[] x = {1, 2, 3, 4, 5, 1, 7, 8, 9, 10}; // x values
 int[] y = {30,34,45,57,77, 89, 100, 111, 123, 145}; // y values

I want the entries in x to be on the x axis and the entries in y to be on the x axis when I put them into achartengine and obtain a graph.

As you can see in the x axis I have two entries of number 1. How do I then combine the corresponding y values so that the data point is (1, 30+89)?

And how can I do this for any number of clashes?

Joel
  • 4,732
  • 9
  • 39
  • 54

2 Answers2

0

Just to gives you some ideas

Code:

        int[] arrayInt = {1, 1, 2, 3, 4, 5, 5, 7, 7, 1, 7};
        Arrays.sort(arrayInt);
        System.out.println("the set with duplication");
        for (int i : arrayInt) 
        System.out.print(i + " ");
        System.out.println();
        Set<Integer> noDuplicateSet = new HashSet<>();
        Set<Integer> duplicateSet = new HashSet<>();

        for (int i = 0; i < arrayInt.length; i++) {
            if (!noDuplicateSet.add(arrayInt[i])) {
                duplicateSet.add(arrayInt[i]);
            }
        }
        System.out.println("your set without any duplicate number");
        noDuplicateSet.stream().forEach((i) -> {
            System.out.print(i + " ");
        });
        System.out.println("\nduplicate numbers set");
        duplicateSet.stream().forEach((i) -> {
            System.out.print(i + " ");
        });

output:

the set with duplication
1 1 1 2 3 4 5 5 7 7 7 
your set without any duplicate number
1 2 3 4 5 7 
duplicate numbers set
1 5 7 
Kick Buttowski
  • 6,709
  • 13
  • 37
  • 58
0

I've resolved this problem by using the google package TreeMultiMap. As follows (without the Package declarations for brevity):

float[] x = {1, 2, 3, 4, 5, 1, 7, 8, 10, 10}; // x values

float[] y = {30, 34, 45, 57, 77, 89, 100, 111, 123, 145}; // y values


ListMultimap<Float, Float> test1map = ArrayListMultimap.create();

for( int t =0 ; t < x.length; t++){
        for(int j = 0; j< x.length; j++){
            if (t !=j && x[t] == x[j]){
                y[j] += y[t];

                test1map.removeAll(x[t]);

            }

        }
        test1map.put(x[t], y[t]);


    }
ArrayList<Float> eureka = new ArrayList<Float>();
ArrayList<Float> eureka2 = new ArrayList<Float>();
int b= 0;
for(Float key : test1map.keys()){
    eureka.add(b, key);
    b++;
}
int v = 0;
for(Float value : test1map.values()){
    eureka2.add(v, value);
    v++;
}