Advertisement
Void-voiD

Untitled

Feb 20th, 2019
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 KB | None | 0 0
  1. public class VandermondeMatrix {
  2. private int[] coefficients;
  3. private int length, result = 1, i, j, k, currentElem, longest, maxLength, currentOffset;
  4. private String string = "";
  5.  
  6. public VandermondeMatrix(int length, int[] coefficients) {
  7. this.length = length;
  8. this.coefficients = coefficients;
  9. }
  10.  
  11. public int countDeterminant() {
  12. if (length > 0) {
  13. for (i = 1; i < length; i++) {
  14. for (j = 0; j < i; j++) result *= coefficients[i] - coefficients[j];
  15. }
  16. return result;
  17. }
  18. else return -1;
  19. }
  20.  
  21. public int LongestElem() {
  22. if (length > 0) {
  23. longest = coefficients[0];
  24. for (i = 1; i < length; i++) {
  25. if (coefficients[i] > longest) longest = coefficients[i];
  26. }
  27. return longest;
  28. }
  29. else return 0;
  30. }
  31.  
  32. public String matrixToString() {
  33. if (length > 0) {
  34. longest = LongestElem();
  35. for (i = 0; i < length; i++) {
  36. currentElem = 1;
  37. maxLength = ("" + longest).length();
  38. currentOffset = longest;
  39. for (j = 0; j < length; j++) {
  40. if (j != length - 1) {
  41. string += currentElem + " ";
  42. for (k = 0; k < maxLength - ("" + currentElem).length(); k++) string += " ";
  43. }
  44. else string += currentElem + "\n";
  45. currentElem *= coefficients[i];
  46. if (j >= 1) {
  47. currentOffset *= longest;
  48. maxLength = ("" + currentOffset).length();
  49. }
  50. }
  51. }
  52. return string;
  53. }
  54. else return "";
  55. }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement