Computer Science, asked by qwer638ry5tyuiop, 4 months ago

Write a program in java to accept 10 numbers in SDA. Arrange them in ascending order without using array sort method.​

Answers

Answered by mayankmonti90
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 anindyaadhikari13
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.

  1. import java.util.*;
  2. public class JavaBrainly {
  3. public static void main(String[] args) {
  4. int a[]=new int[10];
  5. Scanner sc=new Scanner(System.in);
  6. System.out.println("Enter 10 elements in the array..");
  7. for(int i=0;i<10;i++)
  8. {
  9. System.out.print("["+i+"]>> ");
  10. a[i]=sc.nextInt();
  11. }
  12. for(int i=0;i<10;i++)
  13. {
  14. for(int j=i+1;j<10;j++)
  15. {
  16. if(a[i]>a[j])
  17. {
  18. int temp=a[i];
  19. a[i]=a[j];
  20. a[j]=temp;
  21. }
  22. }
  23. }
  24. System.out.println("Array Sorted. Here is the array.");
  25. System.out.println(Arrays.toString(a));
  26. sc.close();
  27. }
  28. }

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