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
A news website uses 32-bit integers to count the number of times an article has been viewed. The website is becoming more popula
Irina-Kira [14]

Answer:

2^32 times as many values can be represented

Explanation:

32-bit. This means that the number is represented by 32 separate one’s and zero’s. 32 bits of 2 possible states = 2^32=4,294,967,296 possible values.

Integer meaning that only whole multiples of one are accepted.

Signed meaning that negative values are accepted. This halves the number of possible positive values (roughly), so the largest number you can represent is 2^31–1=2,147,483,647, but instead of 0, the smallest number you can represent is -2,147,483,648. An unsigned 32-bit integer, by contrast, can represent anything from 0 to 4,294,967,295.

7 0
3 years ago
8. Given the array String[] words, which already contains 1 or more values, write a block of code which counts and returns the n
Vikentia [17]

Answer:

Following are the code to this question:

public class Main//defining a class

{

public static void main(String[] arg)//defining main method

{

  String[] words={"Key","day", "Know", "kind"};//defining array of String words

  int x=0;//defining integer variable for count value

  for(int i=0;i<words.length;i++)//defining for loop for count value

  {

 if(words[i].startsWith("k")||words[i].startsWith("K"))//use if block to check word start from k

  x=x+1;//increment the value of x

  }

System.out.print("The number of letters which starts from k is: "+ x);//print value with message

}

}

Output:

The number of letters which starts from k is: 3

Explanation:

In this code, inside the main method an array of String "words" is defined that hold a value, and in the next step an integer variable "x" is defined, which is used to count the letters, which starts from k.

For this, a for loop is used that counts the value and in this an, if block is defined that uses the "startsWith" method to check the value and increment the value of x and at the last, it prints its value.

7 0
3 years ago
While it might be considered "old-school," which action should you take if you are unsure how a page will print, even after look
coldgirl [10]

Answer:

The correct answer is D

4 0
3 years ago
What will be the output of “AAAAMMMMMHHHVV” using a file compression technique?
jeka94

Answer:

it would be amhv i think i hope it answered u'er question

Explanation:

8 0
4 years ago
Sidney works in the accounting department. His boss just assigned him a task that involves creating budget formulas for the comp
Molodets [167]
The answer is a A. - Excel performs operations based on the order of Precedence
4 0
3 years ago
Other questions:
  • Convert the following binary numbers to decimal numbers. (Show your work) a. 110110 b. 100111 c. 101101
    6·1 answer
  • This is the formula for the future worth of an investment over time with consistent additional monthly payments and a steady rat
    10·1 answer
  • I'm taking a class on how to make a movie, and it offers some apps that would be helpful in the process. The thing is, I don't h
    9·2 answers
  • Refer to the exhibit. One end of the cable is terminated as displayed, and the other end is terminated in accordance with the T5
    7·1 answer
  • HELP WILL GIVE BRAINLIEST
    5·1 answer
  • In cell h13, insert a pmt function to calculate the payments for students who want to pay for their trips in three installments.
    11·1 answer
  • Carbohydrates are a huge source of
    7·2 answers
  • How does Map Put function work in Java? *
    12·1 answer
  • I NEED THIS DONE NOW ASAP, PLS HELP ME
    13·2 answers
  • Help ASAP
    11·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!