Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- import java.io.*;
- import java.math.*;
- import java.util.*;
- class Main {
- public static void main(String args[]){
- double array[] = new double[]{10, 11, 88, 2, 12, 120};
- // double y[]=new double [6];
- double x[]= new double[array.length];
- // Calling getMax() method for getting max value
- double max = getMax(array);
- System.out.println("Maximum Value is: "+max);
- // Calling getMin() method for getting min value
- double min = getMin(array);
- System.out.println("Minimum Value is: "+min);
- double y[]=getMinMax(array);
- System.out.println ();
- System.out.print ("{");
- for(int i=0;i <array.length;i++)
- {
- System.out.print(" "+y[i] +"," );
- }
- System.out.print ("}");
- reverseMinMax(y);
- }
- // Method for getting the maximum value
- public static double getMax(double[] array)
- {
- double maxValue = array[0];
- for(int i=1;i < array.length;i++)
- {
- if(array[i] > maxValue){
- maxValue = array[i];
- }
- }
- return maxValue;
- }
- public static double getMin(double[] array)
- {
- double minValue = array[0];
- for(int i=1;i<array.length;i++)
- {
- if(array[i] < minValue){
- minValue = array[i];
- }
- }
- return minValue;
- }
- // Method for minmax
- public static double [] getMinMax(double[] array)
- {
- double xmax = getMax(array);
- double xmin = getMin(array);
- double ymax=1; double ymin=-1 ;
- double y[]= new double[6];
- for(int i=0;i < array.length;i++)
- {
- y[i] = (ymax-ymin)*(array[i]-xmin)/(xmax-xmin) + ymin;
- }
- System.out.print ("{");
- for(int i=0;i < array.length;i++)
- {
- System.out.print(" "+y[i] +"," );
- }
- System.out.print ("}");
- return y;
- }
- // Method for reverse minmax
- public static double [] reverseMinMax(double[] y)
- {
- double array[] = new double[]{10, 11, 88, 2, 12, 120};
- double xmax = getMax(array);
- double xmin = getMin(array);
- double ymax=1; double ymin=-1 ;
- // double y[]= new double[6];
- double x[]= new double[array.length];
- for(int i=0;i < y.length;i++)
- {
- // y[i] = (ymax-ymin)*(array[i]-xmin)/(xmax-xmin) + ymin;
- x[i]= (xmax-xmin)*(y[i]-ymin)/(ymax-ymin)+xmin;
- }
- System.out.println ();
- System.out.print ("{");
- for(int i=0;i < array.length;i++)
- {
- System.out.print(" "+x[i] +"," );
- }
- System.out.print ("}");
- return x;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement