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]
2 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]2 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
Which two components are configured via software in order for a PC to participate in a network environment
dalvyx [7]

Answer:

IP address and subnet mask.

Explanation:

The two components which are configured via software in order for a personal computer (PC) to participate in a network environment are;

I. IP address: it is an acronym for internet protocol address and can be defined as a unique number assigned to a computer or other network devices, so as to differentiate each device from one another in an active network system. Thus, an IP address is typically used to uniquely identify each computer or network devices connected to the internet or network.

In Computer networking, IP address are classified into two (2) main categories and these are; Local (internal) IP address and Global (external) IP address.

Also, the internet protocol (IP) address comprises of two (2) versions and these are; Internet protocol version 4 (IPv4) and Internet protocol version 6 (IPv6). An example of an IPv4 address is 192.168.1.0.

II. Subnet mask: this is a logical segmentation or subdivision of an internet protocol (IP) network so as to accommodate more hosts (computer systems). An example of a subnet mask is 255.255.0.0.

6 0
2 years ago
To move the first line of text over five spaces and leave the other lines of the paragraph aligned to the left, use the _____ fe
Lera25 [3.4K]

To move the first line of text over five spaces and leave the other lines of the paragraph aligned to the left, use the FIRST LINE INDENT.

<h2>Your answer would be B. First Line Indent</h2><h3><u><em>hope this helps</em></u></h3>
4 0
2 years ago
Read 2 more answers
Suppose that the first goal in a GP problem is to make 3 X1 + 4 X2 approximately equal to 36. Using the deviational variables d1
Scrat [10]

Answer:

d. d1− = 10, d1+ = 0

Explanation:

Given

3X1 + 4X2 +d1− − d1+ = 36

X1 = 6

X2 = 2

Required

Possible values of d1- and d1+

We have:

3X1 + 4X2 +d1− − d1+ = 36

Substitute values for X1 and X2

3 *6 + 4 * 2 + d1- - d1+ = 36

18 + 8 + d1- - d1+ = 36

Collect like terms

d1- - d1+ = 36 - 18 - 8

d1- - d1+ = 10

For the above equation to be true, the following inequality must be true

d1- > d1+

Hence,

(d) is correct

Because:

10 > 0

3 0
2 years ago
(1) Prompt the user for an automobile service. Output the user's input. (1 pt) Ex: Enter desired auto service: Oil change You en
Pavlova-9 [17]

Answer:

In Python:

#1

service = input("Enter desired auto service: ")

print("You entered: "+service)

#2

if service.lower() == "oil change":

   print("Cost of oil change: $35")

elif service.lower() == "car wash":

   print("Cost of car wash: $7")

elif service.lower() == "tire rotation":

   print("Cost of tire rotation: $19")

else:

   print("Invalid Service")

Explanation:

First, we prompt the user for the auto service

service = input("Enter desired auto service: ")

Next, we print the service entered

print("You entered: "+service)

Next, we check if the service entered is available (irrespective of the sentence case used for input). If yes, the cost of the service is printed.

This is achieved using the following if conditions

For Oil Change

<em>if service.lower() == "oil change":</em>

<em>    print("Cost of oil change: $35")</em>

For Car wash

<em>elif service.lower() == "car wash":</em>

<em>    print("Cost of car wash: $7")</em>

For Tire rotation

<em>elif service.lower() == "tire rotation":</em>

<em>    print("Cost of tire rotation: $19")</em>

Any service different from the above three, is invalid

<em>else:</em>

<em>    print("Invalid Service")</em>

<em></em>

6 0
2 years ago
What is MARC? Discuss structure of MARC
nordsb [41]
What do you mean? I don't understand.
7 0
2 years ago
Other questions:
  • What OS has a large market share but is limited because it can be installed only on one particular brand?
    8·2 answers
  • Wide area networks are defined by their ability to
    14·2 answers
  • how to answer the questions on brainly? I've typed my answer in the box but there's no submit button or whatever, and the only t
    14·2 answers
  • Describe the following types of data hazards. RAW WAR WAW
    13·1 answer
  • What's a sentence with the words trickle and resume in it? they can be in any tense. Thanku​
    5·1 answer
  • When you _____ a scroll bar, a shortcut menu appears with commands related to the scroll bar
    10·1 answer
  • Which option is the correct format of placing HTML tags while coding in HTML?
    13·2 answers
  • In how many positions are there nucleotide differences between your query sequence and the sequence of accession AY259214.1
    12·1 answer
  • You can open a movie maker project file any time in a media player. (1 point) true false
    6·1 answer
  • Which option identifies the programming paradigm selected in thr following scenario? A student is writing a science fiction stor
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!