Question

I need it in JAVA Write a program that randomly populates an array of size 100,...

I need it in JAVA

Write a program that randomly populates an array of size 100, sorts it, and then finds the median. The random numbers must be from 0-99 and all integer values. Also since there is an even set of numbers the median is found by taking the mean of the two middle numbers (In other words the 50th and 51st).

You have to code your own sorting method. You may not use a built in java sorter.

Keep in mind the 50th and 51st correspond to the number of items not necessarily the index of the array.

Comment your code

Example Dialog:

Random array

13

80

93

90

46

56

97

88

81

14

23

99

91

8

95

80

86

53

73

38

93

9

95

8

35

49

74

70

8

50

48

2

72

96

17

75

10

10

55

33

39

37

92

12

68

99

98

94

41

43

5

61

71

95

81

89

8

92

8

68

60

14

36

99

36

44

90

45

99

28

22

80

68

37

51

63

63

81

79

24

33

62

8

2

88

61

79

59

48

7

37

57

7

7

36

39

23

48

32

39

Sorted array

2

2

5

7

7

7

8

8

8

8

8

8

9

10

10

12

13

14

14

17

22

23

23

24

28

32

33

33

35

36

36

36

37

37

37

38

39

39

39

41

43

44

45

46

48

48

48

49

50

51

53

55

56

57

59

60

61

61

62

63

63

68

68

68

70

71

72

73

74

75

79

79

80

80

80

81

81

81

86

88

88

89

90

90

91

92

92

93

93

94

95

95

95

96

97

98

99

99

99

99

Median is 52

0 0
Add a comment Improve this question Transcribed image text
Answer #1

MedianTest.java

import java.util.Random;

public class MedianTest {

public static void main(String[] args) {

int a[] = new int[100];

Random r = new Random();

for(int i=0;i<a.length;i++) {

a[i]=r.nextInt(100);

}

System.out.println("Random array: ");

for(int i=0;i<a.length;i++) {

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

}

System.out.println();

buubleSort(a);

System.out.println("Sorted array: ");

for(int i=0;i<a.length;i++) {

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

}

System.out.println();

double median = (a[49] + a[50])/2.0;

System.out.println("Median: "+median);

}

public static void buubleSort(int[] a) {

int n = a.length;

int temp = 0;

for(int i=0; i < n; i++){

for(int j=1; j < (n-i); j++){

if(a[j-1] > a[j]){

//swap the elements!

temp = a[j-1];

a[j-1] = a[j];

a[j] = temp;

}

}

}

}

}

Output:

Random array:
90 41 76 56 75 84 94 37 53 11 39 89 3 45 90 2 80 18 18 19 9 92 3 76 24 15 15 29 42 49 84 25 42 18 3 25 35 58 4 55 68 31 23 19 48 7 50 29 57 19 13 65 30 55 26 7 64 31 35 22 1 98 15 68 64 45 20 72 66 78 50 77 10 56 60 51 93 3 49 9 49 54 40 66 47 65 13 64 40 68 23 47 29 95 82 66 19 39 34 76
Sorted array:
1 2 3 3 3 3 4 7 7 9 9 10 11 13 13 15 15 15 18 18 18 19 19 19 19 20 22 23 23 24 25 25 26 29 29 29 30 31 31 34 35 35 37 39 39 40 40 41 42 42 45 45 47 47 48 49 49 49 50 50 51 53 54 55 55 56 56 57 58 60 64 64 64 65 65 66 66 66 68 68 68 72 75 76 76 76 77 78 80 82 84 84 89 90 90 92 93 94 95 98
Median: 43.5

Add a comment
Know the answer?
Add Answer to:
I need it in JAVA Write a program that randomly populates an array of size 100,...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • The ExceptionLab class provided: – Creates an array of 100 elements and fills it with random...

    The ExceptionLab class provided: – Creates an array of 100 elements and fills it with random numbers from 1 to 100. – It asks the user for an index value between 0 and 99. – Prints the element at that position. – If a number > 99 is entered by the user, the class will abort with an ArrayIndexOutOfBoundsException • Modify the ExceptionLab: – Add a try-catch clause which intercepts the ArrayIndexOutOfBounds and prints the message: Index value cannot be...

  • RANGES FREQUENCY RELATIVE FREQUENCY CUMULATIVE REL. FREQ. 1 - 10 11 - 20 21 - 30 31 - 40...

    RANGES FREQUENCY RELATIVE FREQUENCY CUMULATIVE REL. FREQ. 1 - 10 11 - 20 21 - 30 31 - 40 41 - 50 51 - 60 61 - 70 71 - 80 81 - 90 91 - 100 '= 100 DATA VALUES?? SO, WHAT DOES A FREQUENCY TABLE TELL US? If you wrote each of the above data values on a ping pong ball,, put them in a jar and blindly pulled one out: What is the probability that this ball...

  • Write a python nested for loop that prints out the following pattern 100 99 98 97...

    Write a python nested for loop that prints out the following pattern 100 99 98 97 96 95 94 93 92 91 90 89 88 87 86 85 84 83 82 81 80 79 78 77 76 75 74 73 72 71 70 69 68 67 66 65 64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33...

  • Consider the below matrixA, which you can copy and paste directly into Matlab.

    Problem #1: Consider the below matrix A, which you can copy and paste directly into Matlab. The matrix contains 3 columns. The first column consists of Test #1 marks, the second column is Test # 2 marks, and the third column is final exam marks for a large linear algebra course. Each row represents a particular student.A = [36 45 75 81 59 73 77 73 73 65 72 78 65 55 83 73 57 78 84 31 60 83...

  • I need to develop the 7 functions below into the main program that's given on top...

    I need to develop the 7 functions below into the main program that's given on top Write a C program to create array, with random numbers and perform operations show below. Il Project 3 (53-20). 1 Projects CS5,00 This file contains the function Programcution Dagine and one include <timo // Defining some constants definer_SIZE 20 define LOVE LIMIT 1 eine UPR UNIT define TALSE eine Tut 1 wold randomizery (int[], int, Int, int) wold pinay in. St, Int); En find...

  • Use C++ (2D Array) Write a program which: 1. Assigns data given below into the 2D...

    Use C++ (2D Array) Write a program which: 1. Assigns data given below into the 2D array of integers which is 10x10. 2. Prints out the contents of the 2D array after assigning the data to make sure correct data was assigned. 3. Figures out and prints out the square root of the sum of ALL the elements in the 2D array. 4. Figures out and prints out the average of ALL THE ELEMENTS in the 2D array. 5. Figures...

  • Calculate the range, mean, mode, median, Standard deviation Calculate the skewness and kurtosis for the above...

    Calculate the range, mean, mode, median, Standard deviation Calculate the skewness and kurtosis for the above data and interpret the data. The following is data collected from the daily salary employees of ZZ COMPANY.. 68 19 43 11 37 30 19 67 65 34 96 23 93 73 46 39 21 12 89 52 33 21 18 57 80 56 91 62 56 48 84 23 78 96 49 36 90 42 65 15 43 36 65 59 34 71...

  • Please show how you did this in excel. :13-19 Every home football game for the past...

    Please show how you did this in excel. :13-19 Every home football game for the past eight years at Eastern State University has been sold out. The revenues from ticket sales are significant, but the sale of food, beverages, and souvenirs has contrib- uted greatly to the overall profitability of the football program. One particular souvenir is the football pro- gram for each game. The number of programs sold at each game is described by the following probabil- ity distribution:...

  • NUMBER OF PEOPLE 10.2 10.0 10.1 8.5 10.2 8.2 8 Source: United States Census. 11. In...

    NUMBER OF PEOPLE 10.2 10.0 10.1 8.5 10.2 8.2 8 Source: United States Census. 11. In the Sanitary District of Chicago, operating engineers are hired on of a competitive civil-service examination. In 1966, there were 223 appl for 15 jobs. The exam was held on March 12; the test scores are s arranged in increasing order. The height of each bar in the histogram next page) shows the number of people with the correspondin examiners were charged with rigging the...

  • 1. Forecast demand for Year 4. a. Explain what technique you utilized to forecast your demand....

    1. Forecast demand for Year 4. a. Explain what technique you utilized to forecast your demand. b. Explain why you chose this technique over others. Year 3 Year 1 Year 2 Actual Actual Actual Forecast Forecast Forecast Demand Demand Demand Week 1 52 57 63 55 66 77 Week 2 49 58 68 69 75 65 Week 3 47 50 58 65 80 74 Week 4 60 53 58 55 78 67 57 Week 5 49 57 64 76 77...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT