×
FREE ASSISTANCE FOR THE INQUISITIVE PEOPLE
Tutorial Topics
X
softetechnologies
Find the highest and the lowest character in a word through java Sum of the diagonal elements of 2D Array
Advance Array Examples In Java - Java
2931    Arnab De    11/09/2018

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}



softetechnologies

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] + "  ");
        }
    }
}
softetechnologies

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

Find the highest and the lowest character in a word through java Sum of the diagonal elements of 2D Array
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.
Enter New Comment
Comment History
No Comment Found Yet.
Albert Einstein
Imagination is more important than knowledge.
Albert Einstein
116
59.22
Today So Far
Total View (Lakh)
softetechnologies
26/05/2018     44273
01/01/2018     36695
25/06/2018     36199
28/06/2017     34734
02/08/2017     33284
01/08/2017     27699
06/07/2017     27446
15/05/2017     27055
14/07/2017     22750
11/09/2018     21388
softetechnologies