Advance Array Examples In Java
11-09-2018    147 times
Advance Array

Write a program to input an integer array A[] of n size. Sort the array in ascending order. Then input another number from the user and replace all the numbers less than that inputted number by their reverse.




Example :

If A[] = {38, 25, 16, 91, 5, 12}then, array after sorting is {5, 12, 16, 25, 38, 91} If the number entered = 20 then, after replacing all the numbers less than 20 with their reverse, final Output is {5, 21, 61, 25, 38, 91}



Tutorial at home

import java.util.*;
public class ArraySortAdvance
{
    public static void main(String []args)
    {
        int i,j,k,l,p;
        Scanner sc=new Scanner(System.in);
        System.out.print("Enter A Nos : ");
        int n=sc.nextInt();
        int []A=new int[n];
        System.out.println("Enter A Nos. of Array : ");
        for(i=0;i<n;i++)
        {
            A[i]=sc.nextInt();
        }
        for(i=0;i<n-1;i++)
        {
            for(j=i+1;j<n;j++)
            {
                if(A[i]>A[j])
                {
                    k=A[i];
                    A[i]=A[j];
                    A[j]=k;
                }
            }
        }
        System.out.println("Sorted Array : ");
        for(i=0;i<n;i++)
        {
            System.out.print(A[i] + "  ");
        }
        System.out.print("\n Enter A No : ");
        k=sc.nextInt();
        for(i=0;i<n;i++)
        {
            if(A[i]<k)
            {
                if(A[i]>9)
                {
                    l=0;
                    while(A[i]>0)
                    {
                        l=l*10 + (A[i]%10);
                        A[i] /= 10;
                    }
                    A[i]=l;
                }
            }
            else
            {
                break; //As Array is sorted
            }
        }
        System.out.println("Resultant Array : ");
        for(i=0;i<n;i++)
        {
            System.out.print(A[i] + "  ");
        }
    }
}
Tutorial at home

Enter the length of Array : 6
Enter A Nos. of Array :
23
43
3
25
19
16
Sorted Array :
3 16 19 23 25 43
Enter A No : 22
Resultant Array :
3 61 91 23 25 43

softetechnologies
    Author Details
Arnab De
I have over 16 years of experience working as an IT professional, ranging from teaching at my own institute to being a computer faculty at different leading institute across Kolkata. I also work as a web developer and designer, having worked for renowned companies and brand. Through tutorialathome, I wish to share my years of knowledge with the readers.
    Related Post
  Query About the post