0

I have an equation : A = b^2 + 4*c^2

I change a value of 'b' and 'c' like this: b=1,2,3,4,5,... and c=1,2,3,4,5,... and I put them in equation.

I want to create a table of results (as an output), something like this:

      b  c  A
      1  1  5
      1  2  17
      2  1  8
      2  2  20
      4  1  20
      ........

However, I want to have table sorted from smallest value of A towards the biggest. Note that it can occur that different pairs of b and c give the same A. I want to create table like that for 10 different values of A.

My problem is that I don't know how to 'link' value A with proper value of b and c, when I try to sort the table

1
  • 1
    create a class that holds the three variables Commented May 14, 2013 at 21:25

2 Answers 2

5

You may create a class that represent three values and then sort.

class Tuple implement Comparable<Tuple>{

     int a, b, c;
     //....
     int compareTo(Tuple tuple) {
         return Integer.compare(a, tuple.a);
     }

}

Tuple[] tuples;
// ...
Arrays.sort(tuples);
Sign up to request clarification or add additional context in comments.

Comments

1

One Simple method:

Make a 3 column array, and when you sort by the A column, take the rest of the row with you.

There are many possibilities.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.