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
What is the simplest unit of a compound that maintains all the characteristics of the compound<br> ?
vlada-n [284]
A molecule is the simplest unit of a compound.
3 0
3 years ago
Wht is RAM called Random Access memory and ROM IS called Read only memory​
nasty-shy [4]

Answer: Computer memory is of two basic type – Primary memory(RAM and ROM) and Secondary memory(hard drive,CD,etc.). Random Access Memory (RAM) is primary-volatile memory and Read Only Memory (ROM) is primary-non-volatile memory.

Explanation: Hope this helps :)

6 0
3 years ago
What is the name of the car on the right?
Kaylis [27]

A buggati or however u spell it


5 0
3 years ago
Read 2 more answers
A microwave is the only electric device in a 120-volt circuit. If the circuit has 7. 5 amps of current, what is the electric pow
sergij07 [2.7K]

The only electric appliance in a 120-volt circuit is a microwave. If the circuit has a 7. 5 amp current, the microwave's electric output is 900 watts.

<h3>Explain about the microwave's electric output?</h3>

As was previously said, 1000W is the most common microwave wattage . The real power usage of a 1000W microwave, or its average input wattage, is 1402.7W. In a microwave, it is always more important to pay attention to the input wattage than the output wattage.

The energy that can be used in a microwave to heat and cook food is represented by this number. Typically, the power output is expressed in Watts, for example, 900 Watts. The appliance's whole wattage consumption used to produce microwave energy is the input.

A microwave can consume anywhere from 600 to 1,000 watts (W) of power. When connected to a 120-volt outlet, microwaves draw roughly 10 amps. The largest influence on how much electricity your microwave uses over time is how frequently you use it.

To learn more about microwave's electric output refer to:

brainly.com/question/13943474

#SPJ4

4 0
1 year ago
What is the correct syntax to take the first five characters from the cell A2 and place it to its right in cell A3? =RIGHT(A3,5)
vfiekz [6]

Answer:=LEFT(A2,5)

Explanation:

8 0
2 years ago
Read 2 more answers
Other questions:
  • Which term is used to mean the methods of a predator uses to befriend youth online?
    6·2 answers
  • Write a program to calculate and return total surface area of a box using FUNCTION _END FUNCTION.​
    15·1 answer
  • Are one of the greatest features of Photoshop that allow nondestructive editing of images.
    6·1 answer
  • I analyze data, as a consultant, for companies making important business decisions. In order to get my point across, which of th
    11·1 answer
  • Who ever likes Pokemon an wants to help me please comment and I will Give the room for My Assignment
    9·1 answer
  • While the names for Web addresses, or URLs, are not case-sensitive, the names for files you create for the Web are. 
    11·1 answer
  • How has information technology made piracy possible
    11·1 answer
  • Powerful IT security systems are needed to defend against what appears to be authorized access to a network or application. Sele
    6·1 answer
  • If you were an architect planning on building a large scale Municipal complex what type of engineer would you identify as essent
    10·1 answer
  • Which one of the following media is unguided media ?​
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!