1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
gregori [183]
3 years ago
5

write a 〕ava program to sort a random list of 10 numbers entered b y user in an array using Selection Sort technique

Computers and Technology
1 answer:
Anton [14]3 years ago
5 0

Here is code in java to perform selection sort.

// import library

import java.util.*;

import java.lang.*;

import java.io.*;

class Solution

{

public static void main (String[] args) throws java.lang.Exception

{

   try{

     // creating object of Solution class

       Solution obj=new Solution();

    // creating object of Scanner class to read input

       Scanner sc=new Scanner(System.in);

    // create array of size 10

    int arr[]=new int[10];

       System.out.println("Please Enter 10 numbers :");

    // reading input from user

       for(int i=0;i<10;i++)

       {

           arr[i]=sc.nextInt();

       }

    // calling sort_fun with object "obj" to sort array

       obj.sort_fun(arr);

// printing the array after selection sort

 System.out.println("Array after performing selection sort:");

 for (int i=0; i<10; ++i)

  System.out.print(arr[i]+" ");

 System.out.println();

   }catch(Exception ex){

       return;}

}

// creating function to perform selection sort

public static void sort_fun(int arr[])

{

 for (int i = 0; i < 10-1; i++)

 {

  int m_idx = i;

  for (int j = i+1; j < 10; j++)

   if (arr[j] < arr[m_idx])

    m_idx = j;

    // find the minimum element and put them in the beginning

  int temp = arr[m_idx];

  arr[m_idx] = arr[i];

  arr[i] = temp;

 }

}

}

Explanation:

First create an object of "Solution" class. Then create an object of "Scanner" class to read input from user.After this create an array of size 10 of type integer and read 10 value from user in the array.In the sort_fun(),it will find the smallest element of unsorted array and put it in the beginning of the array. Then it find the second smallest number and put it after the first element. Similarly it will find the next element and put it after second element.When the loop end, the array will be sorted.

Output:

Please Enter 10 numbers :

45 34 12 90 84 1 4 56 12 6

Array after performing selection sort:

1 4 6 12 12 34 45 56 84 90

You might be interested in
What number is represented as a binary code of 101110
mariarad [96]

Answer:

46 i think

Explanation:

sorry if thats wrong

4 0
2 years ago
Read 2 more answers
What is one rover that landed on mars but not pathfinder or curosity?
Gwar [14]
A aham akzm shka agzb. Ni
3 0
3 years ago
Read 2 more answers
XML Schemas consist of:
Contact [7]
None of the above is correct

4 0
3 years ago
What is a computer memory <br>​
Alex_Xolod [135]

Answer:

In computing, memory is a device or system that is used to store information for immediate use in a computer or related computer hardware and digital electronic devices. The term memory is often synonymous with the term primary storage or main memory. An archaic synonym for memory is store.

5 0
3 years ago
Read 2 more answers
चार फरक छुट्याउनुहोस् ।) 3. Write down any four provisions of cyber ethic साइबर नैतिकताका कुनै चार प्रावधानहरु लेख्नुहोस् ।​
Kruka [31]

Answer:

Five provisions of cyber ethics are:

Your computer or system should not be used to harm others. Your cyber knowledge should not be used to steal other people's resources. One should not use or copy softwares for which you have not paid. ... Never use other people's resources without their consent.

7 0
3 years ago
Other questions:
  • In database systems, the dbms enforces rules about which user can perform which action when. The rules are known as ________.
    10·1 answer
  • What is the best overall approach to education and career development for IT professionals?
    14·1 answer
  • Why might location be important when searching for a job?
    10·2 answers
  • Define the term Frame Rate.
    12·1 answer
  • What are three reasons teens might start drinking alcohol??
    7·2 answers
  • PLEASE HELP!!!!!!!!!!!
    15·2 answers
  • Examine the following declarations and definitions for the array-based implementations for the Stack and Queue ADTs. Assume that
    14·1 answer
  • If you play video games, please answer these questions it’s for a survey for my game development class!!
    5·1 answer
  • It is a type of web page that allows you to share your ideas experiences and beliefs
    9·1 answer
  • Write a function named count_vowels that accepts two arguments: a string and an empty dictionary. The function should count the
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!