/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package sortarray;

/**
 *
 * @author User-admin
 */
import java.util.Scanner;
import java.util.stream.IntStream;
public class Sortarray {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) 
  {
       
        Scanner scan = new Scanner(System.in);
    
          System.out.printf("Enter the Number of Array\r\n");
          int numberInArray  = scan.nextInt();

          int[] actualValues = new int[numberInArray];
          
          int numberToUse = numberInArray - 1;

          for (int i = 1;i<=numberToUse;i++)
          {  
                  
           int values = addToArray(i);
                                  
            boolean contains = IntStream.of(actualValues).anyMatch(x -> x == values);
                                     
                                if(contains==true)
                                {
                                     System.out.printf("Please Enter Only Uniq Number\r\n" );
                                    addToArray(i) ;
                                   
                                    
                                }
                                else 
                                {

                                  actualValues[i] = values;
                                }
            
        }
    addNumber(numberInArray, actualValues);
    
    System.out.println("The order In which they where Entered \r\n");
    for (int i = 0; i < actualValues.length; i++) 
      {
    System.out.println( actualValues[i]);
      };
   
   System.out.println("The reverse order In which they where Entered \r\n");
for(int i = 0; i < actualValues.length / 2; i++)
        {
            int temp = actualValues[i];
            actualValues[i] = actualValues[actualValues.length - i - 1];
            actualValues[actualValues.length - i - 1] = temp;
        }


    }

     static int addToArray( int index) 
    {    Scanner scan = new Scanner(System.in); 
           System.out.printf("Enter Number \r\n" );
            int values = scan.nextInt();
            return values;
    }
    public static void addNumber(int numberToLoop, int[] theArray) 
    {
      int sum = 0;
            for (int i = 0;i<theArray.length;i++) 
            {
             sum =  sum + theArray[i];
            }
       System.out.printf("Sum of Array \r\n" );
       System.out.printf( sum + "\r\n" );


 int temp;
   for (int i = 1; i == theArray.length; i++) 
   {

  for (int j = i; j > 0; j--)
        {
          if(theArray[j] < theArray [j -1]) 
          {
            temp = theArray[j];
            theArray[j] = theArray[j - 1];
            theArray[j - 1] = temp;



          }


        }
    }
    System.out.println("List Array in Descending Order \r\n");
for (int i = 0; i < theArray.length; i++) {
    System.out.println( theArray[i]);
};

    int lastValue =  theArray.length - 1;
    System.out.println("First Item in Array  \r\n"+theArray[0]);
    System.out.println("last Item in Array  \r\n"+ theArray[lastValue]);
}
}



    




  










  






