Question

In: Computer Science

There's an array named score, 90, 98, 92, 88, 100, 80 are the elements in this...

There's an array named score, 90, 98, 92, 88, 100, 80 are the elements in this array.

Please write a Java program to declare and sort this array (use selection sort).

Solutions

Expert Solution

Code:

public class Main
{
public static void selectionSort(int[] array){ //method of selection sort
for(int i=0;i<array.length-1;i++)
{
int index=i;
for(int j=i+1;j<array.length;j++)
{
if (array[j]<array[index])
{
index=j; //searching for lowest index
}
}
int smallerNumber = array[index];   
array[index] = array[i];
array[i] = smallerNumber;
}
}
  
   public static void main(String[] args) {
       int [] score = {90,98,92,88,100,80}; //declare and initialize array named score
selectionSort(score); //sorting array using selection sort by calling selectionSort function

System.out.println("Result after Selection Sort");
for(int i=0;i<score.length;i++) //print array after sort
{
System.out.print(score[i]+" ");
}
   }
}

Output:


Related Solutions

Scores are 92, 68, 88, 96, 72, 88, 80, 64, 74, 92, 100, 84   What is...
Scores are 92, 68, 88, 96, 72, 88, 80, 64, 74, 92, 100, 84   What is the IQR? 19 19.5 20.5 20 6
92 99 96 94 94 94 90 95 90 89 89 80 83 88 88 1.  What...
92 99 96 94 94 94 90 95 90 89 89 80 83 88 88 1.  What is the n?   __________ 2.  What is ∑x ? __________ 3.  What is ∑x2? __________ 4.  What is (∑x)2? __________ 5.  What is the range?  __________ 6.  What is the mean?  __________ 7.  What is the median?  __________ 8.  What is the mode?  __________ 9.  What is the variance?  __________ 10.  What is the standard deviation?  __________ 11.  If Kara scored a 90 (x)….What is her Z-score?  __________ 12.  If Sara scored a 95….What is her T-score?  __________ 13.  Mark scored an 88 (one of...
The score of a course out of 100 in Winter of 10 students are 48, 92,...
The score of a course out of 100 in Winter of 10 students are 48, 92, 47, 44, 94, 18, 95, 67, 74, 64 a. Calculate Q1, Q3 and IQR of the data. b. Find the mean, median and standard deviation c. Determine whether the smallest value of this data set is an outlier. d. Comment the shape of the distribution.
Test scores on a recent statistics test are listed below. 80 79 92 75 88 35...
Test scores on a recent statistics test are listed below. 80 79 92 75 88 35 98 91 90 81 32 50 59 66 68 95 42 18 a) Find the mean and median of the data set. b) Find the standard deviation and the range c) Find the five number summary for the data. d) Construct a box plot for the data. e) Are there any outliers? Justify your answer. f) Describe the distribution of the data. g) Which...
a) Given an array A [ 20, 60 , 80 , 90 , 90 , 100 , 110 ] and key = 90 ; in how many iterations would the liner search and binary search reach to the key ? And why?
Q : Give a brief answer to the following questions: : a) Given an array A [ 20, 60 , 80 , 90 , 90 , 100 , 110 ] and key = 90 ; in how many iterations would the liner search and binary search reach to the key ? And why ? (2 marks ) b) What is the name of the algorithm that is able to find the kth smallest element in an unordered list (1 mark)...
Write a function named findIndex that takes an array of integers, the number of elements in...
Write a function named findIndex that takes an array of integers, the number of elements in the array, and two variables, such that it changes the value of the first to be the index of the smallest element in the array, and changes the value of the second to be the index of the largest element in the array. Please complete this in C++, using pass by reference
Write a function named findIndex that takes an array of integers, the number of elements in...
Write a function named findIndex that takes an array of integers, the number of elements in the array, and two variables, such that it changes the value of the first to be the index of the smallest element in the array, and changes the value of the second to be the index of the largest element in the array. Please complete this in C++
Write a PHP program that checks the elements of a string array named $Passwords. Use regular...
Write a PHP program that checks the elements of a string array named $Passwords. Use regular expressions to test whether each element is a strong password. For this exercise, a strong password must have at least one number, one lowercase letter, one uppercase letter, no spaces, and at least one character that is not a letter or number. (Hint: Use the [^0-9A-Za-z] character class.) The string should also be between 8 and 16 characters long. The $Passwords array should contain...
Suppose 90% of a sample of 100 randomly selected homes in Town A and 80% of...
Suppose 90% of a sample of 100 randomly selected homes in Town A and 80% of a sample of 50 randomly selected homes in Town B rely on the public water supply for drinking water. Compute the test statistic for a hypothesis test to compare the population proportion of homes that rely on the public water supply for drinking water in Town A to the proportion in Town B. Assume that the conditions for a hypothesis test for the difference...
E.g., given an array-backed list lst containing the elements [0, 1, 2, 3, 4, ..., 98,...
E.g., given an array-backed list lst containing the elements [0, 1, 2, 3, 4, ..., 98, 99], the following code: for x in lst.poly_iter(2, 3, 4): print(x) will produce the output: 4 9 18 31 48 69 94 Programming rules: You must adhere to the same rules when using the built-in Python list as you did in the ArrayList lab. You may not use any other data structures (this includes the built-in Python list). class ArrayList: def __init__(self): self.data =...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT