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
denpristay [2]
3 years ago
15

1. The following programs require using arrays. For each, the input comes from standard input and consists of N real numbers bet

ween 0.0 and 1.0. \ a. Print the median element. b. Print the element that occurs most frequently. c. Print the element closest to 0. d. Print all the numbers greater than the average. e. Print the N elements in random order. f. Print histogram (with, say 10 bins of size 0.1).
Computers and Technology
1 answer:
Mamont248 [21]3 years ago
3 0

Answer:

import java.util.*;

import java.io.BufferedReader;

import java.io.IOException;

import java.io.InputStreamReader;

import java.util.Arrays;

class GFG

{

  // Function for calculating mean

  public static double findMean(double a[], int n)

  {

      int sum = 0;

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

          sum += a[i];

 

      return (double)sum / (double)n;

  }

  // Function for calculating median

  public static double findMedian(double a[], int n)

  {

      // First we sort the array

      Arrays.sort(a);

      // check for even case

      if (n % 2 != 0)

      return (double)a[n / 2];

 

      return (double)(a[(n - 1) / 2] + a[n / 2]) / 2.0;

  }

  public static double findMode(double a[], int n)

{

// The output array b[] will

// have sorted array

//int []b = new int[n];

 

// variable to store max of

// input array which will

// to have size of count array

double max = Arrays.stream(a).max().getAsDouble();

 

// auxiliary(count) array to

// store count. Initialize

// count array as 0. Size

// of count array will be

// equal to (max + 1).

double t = max + 1;

double[] count = new double[(int)t];

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

{

count[i] = 0;

}

 

// Store count of each element

// of input array

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

{

count[(int)(10*a[i])]++;

}

 

// mode is the index with maximum count

double mode = 0;

double k = count[0];

for (int i = 1; i < t; i++)

{

if (count[i] > k)

{

k = count[i];

mode = i;

}

}

return mode;

}

public static double findSmallest(double [] A, int total){

Arrays.sort(A);

return A[0];

}

 

public static void printAboveAvg(double arr[], int n)

{

 

// Find average

double avg = 0;

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

avg += arr[i];

avg = avg / n;

 

// Print elements greater than average

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

if (arr[i] > avg)

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

System.out.println();

}

 

public static void printrand(double [] A, int n){

Arrays.sort(A);

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

System.out.print(A[0]+"/t");

}

System.out.println();

}

 

public static void printHist(double [] arr, int n) {

 

for (double i = 1.0; i >= 0; i-=0.1) {

System.out.print(i+" | ");

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

 

// if array of element is greater

// then array it print x

if (arr[j] >= i)

System.out.print("x");

 

// else print blank spaces

else

System.out.print(" ");

}

System.out.println();

}

// print last line denoted by ----

for(int l = 0; l < (n + 3); l++){    

System.out.print("---");

}

 

System.out.println();

System.out.print(" ");

 

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

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

}

}

  // Driver program

  public static void main(String args[]) throws IOException

  {

      //Enter data using BufferReader

BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

double [] A = new double[100];

int i=0;

System.out.println("Enter the numbers(0.0-1.0) /n Enter 9 if u have entered the numbers. /n");

do

{

A[i++]=Double.parseDouble(br.readLine());

}while(A[i-1]==9);

      i--;

      System.out.println("Average = " + findMean(A,i) );

      System.out.println("Median = " + findMedian(A,i));

      System.out.println("Element that occured most frequently = " + findMode(A,i));

      System.out.println("number closest to 0.0 =" + findSmallest(A,i));

      System.out.println("Numbers that are greater than the average are follows:");

      printAboveAvg(A,i);

      System.out.println("Numbers in random order are as follows:");

      printrand(A,i);

      System.out.println("Histogram is bellow:");

      printHist(A,i);

  }

}

Explanation:

You might be interested in
If an M:N relationship is mandatory on both sides, and if both relations resulting from the entities involved in the relationshi
vivado [14]

Answer:

0

Explanation:

In the problem above, the relationship that exists between M and N is discovered to be on each side of the system. Furthermore, it was stated that the outcome of the relationship also has approximately 3 records. This shows that there is no record for the bridge that is formed as a result of the relationship.

4 0
3 years ago
Which extension is appropriate for Word document templates?
expeople1 [14]
The answer to this question is A
8 0
2 years ago
Read 2 more answers
"Bullet Lists" can be which of the following?
MariettaO [177]

Answer:

letters and numbered

Explanation:

7 0
3 years ago
Read 2 more answers
Sharon is responsible for the security on web applications. She’s looking to see if all applications have input validation. What
LiRa [457]

Answer:

Options Include:

<em>A) Server-side validation </em>

<em>B) Client-side validation </em>

<em>C) Validate in trust </em>

D) Client-side and server-side validation

<em>Client-side and server-side validation is Correct</em>

Explanation:

The best option is to validate the client side with the server side. Using these together would provide the best testing option for Sharon.

<em>This keeps user feedback instantly without wasting postbacks while also protecting against JavaScript disabled users. That's how the validation controls for ASP.NET operate. </em>

This is definitely not over-engineering as there are risks of using one without the other.

Individual validation on the server side and individual validation on the client side are both incorrect. Trust validation is not a form of validation.

4 0
3 years ago
Which group and tab do you need to be in to separate text into two columns? Paragraph group and Insert tab Page Layout group and
WARRIOR [948]

Answer: Page setup group and page layout tab

Explanation:

:)

7 0
2 years ago
Other questions:
  • You are reluctant to write an extra credit book report because you are afraid that your language and punctuation skills are not
    11·1 answer
  • PASSAGE: The picnic had been scheduled for weeks in advance. The Morris family was looking forward to some fun and relaxation wi
    12·1 answer
  • List of programming languages and their typing
    5·2 answers
  • Black Ops 3 For Ps4 Players Here
    7·1 answer
  • Define
    15·1 answer
  • Write an if-else statement that displays 'Speed is normal' if the speed variable is within the range of 24 to 56. If the speed v
    5·1 answer
  • Write an HTML document which contains two text fields, a button, and a div. The first text field should be labeled “Temperature”
    10·1 answer
  • Which of the following might cause a shift from PPF1 to PPF2? I. A new source of high quality denim fabric. II. A new lighter me
    12·1 answer
  • Write a c program to count the total number of commented characters and words in a c file taking both types of c file comments (
    11·2 answers
  • In relation to data science,advances in technology has made it more feasible to do what
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!