Advertisement
biswasrohit20

java

Mar 30th, 2021
251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.64 KB | None | 0 0
  1. import java.util.Scanner;
  2. import java.io.*;
  3. import java.math.*;
  4. import java.util.*;
  5.  
  6. class Main {
  7.  
  8. public static void main(String args[]){
  9. double array[] = new double[]{10, 11, 88, 2, 12, 120};
  10. // double y[]=new double [6];
  11. double x[]= new double[array.length];
  12. // Calling getMax() method for getting max value
  13. double max = getMax(array);
  14. System.out.println("Maximum Value is: "+max);
  15.  
  16. // Calling getMin() method for getting min value
  17. double min = getMin(array);
  18. System.out.println("Minimum Value is: "+min);
  19. double y[]=getMinMax(array);
  20. System.out.println ();
  21.  
  22. System.out.print ("{");
  23.  
  24. for(int i=0;i <array.length;i++)
  25. {
  26. System.out.print(" "+y[i] +"," );
  27. }
  28. System.out.print ("}");
  29.  
  30. reverseMinMax(y);
  31.  
  32. }
  33. // Method for getting the maximum value
  34. public static double getMax(double[] array)
  35. {
  36. double maxValue = array[0];
  37. for(int i=1;i < array.length;i++)
  38. {
  39. if(array[i] > maxValue){
  40. maxValue = array[i];
  41. }
  42. }
  43. return maxValue;
  44. }
  45.  
  46. public static double getMin(double[] array)
  47. {
  48. double minValue = array[0];
  49. for(int i=1;i<array.length;i++)
  50. {
  51. if(array[i] < minValue){
  52. minValue = array[i];
  53. }
  54. }
  55. return minValue;
  56. }
  57. // Method for minmax
  58. public static double [] getMinMax(double[] array)
  59. {
  60. double xmax = getMax(array);
  61. double xmin = getMin(array);
  62. double ymax=1; double ymin=-1 ;
  63. double y[]= new double[6];
  64. for(int i=0;i < array.length;i++)
  65. {
  66. y[i] = (ymax-ymin)*(array[i]-xmin)/(xmax-xmin) + ymin;
  67. }
  68.  
  69. System.out.print ("{");
  70.  
  71. for(int i=0;i < array.length;i++)
  72. {
  73. System.out.print(" "+y[i] +"," );
  74. }
  75. System.out.print ("}");
  76.  
  77. return y;
  78. }
  79. // Method for reverse minmax
  80. public static double [] reverseMinMax(double[] y)
  81. {
  82.  
  83. double array[] = new double[]{10, 11, 88, 2, 12, 120};
  84. double xmax = getMax(array);
  85. double xmin = getMin(array);
  86.  
  87.  
  88. double ymax=1; double ymin=-1 ;
  89. // double y[]= new double[6];
  90. double x[]= new double[array.length];
  91.  
  92. for(int i=0;i < y.length;i++)
  93. {
  94. // y[i] = (ymax-ymin)*(array[i]-xmin)/(xmax-xmin) + ymin;
  95. x[i]= (xmax-xmin)*(y[i]-ymin)/(ymax-ymin)+xmin;
  96.  
  97. }
  98. System.out.println ();
  99.  
  100. System.out.print ("{");
  101.  
  102. for(int i=0;i < array.length;i++)
  103. {
  104. System.out.print(" "+x[i] +"," );
  105. }
  106. System.out.print ("}");
  107.  
  108. return x;
  109. }
  110. }
  111.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement