Sunday, 12 March 2023

1. Write a program to sort the elements of one dimensional array. Read value of array elements through command line argument.



class Program1
{
    public static void main(String args[])
    {
        int arr[] = new int[args.length];
        int temp;
       
        for(int i=0; i<args.length; i++)
        {
            arr[i] = Integer.parseInt(args[i]);
            System.out.print(arr[i] + " ");
        }
       
        for(int i=0; i<arr.length; i++)
        {
            for(int j=0; j<arr.length; j++)
            {
                if(arr[i] < arr[j])
                {
                    temp = arr[i];
                    arr[i] = arr[j];
                    arr[j] = temp;
                }
            }
        }
       
        System.out.println("\n sorted value: ");
       
        for(int i=0; i<arr.length; i++)
        {
            System.out.print(arr[i] + " ");
        }
    }
}


No comments:

Post a Comment

python programs

1. sum of two number