Write a program in java to accept 10 numbers in SDA. Arrange them in ascending order without using array sort method.
Answers
Answered by
0
Answer:
Write a program in java to accept 10 numbers in SDA. Arrange them in ascending order without using array sort method.
Explanation:
Write a program in java to accept 10 numbers in SDA. Arrange them in ascending order without using array sort method.
Answered by
4
Required Answer:-
Question:
- Write a program in Java to accept 10 numbers in SDA. Arrange them in ascending order without using Arrays.sort() method.
Solution:
Here is the code.
- import java.util.*;
- public class JavaBrainly {
- public static void main(String[] args) {
- int a[]=new int[10];
- Scanner sc=new Scanner(System.in);
- System.out.println("Enter 10 elements in the array..");
- for(int i=0;i<10;i++)
- {
- System.out.print("["+i+"]>> ");
- a[i]=sc.nextInt();
- }
- for(int i=0;i<10;i++)
- {
- for(int j=i+1;j<10;j++)
- {
- if(a[i]>a[j])
- {
- int temp=a[i];
- a[i]=a[j];
- a[j]=temp;
- }
- }
- }
- System.out.println("Array Sorted. Here is the array.");
- System.out.println(Arrays.toString(a));
- sc.close();
- }
- }
Explanation:
- Generally, Arrays can be sorted directly by using Arrays.sort() function. But the question says not to use Arrays.sort() function. In this approach, the given array is sorted using selection sort algorithm.
Output is attached for verification.
Attachments:
Similar questions