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
Kipish [7]
3 years ago
10

Take the average of some numbers. Show all the numbers that are below average. You can assume that there will not be more than 2

0 numbers entered. For example: Enter a weight (0 to stop): 1 Enter a weight (0 to stop): 2 Enter a weight (0 to stop): 3 Enter a weight (0 to stop): 4 Enter a weight (0 to stop): 5 Enter a weight (0 to stop): 6 Enter a weight (0 to stop): 7 Enter a weight (0 to stop): 8 Enter a weight (0 to stop): 9 Enter a weight (0 to stop): 10 Enter a weight (0 to stop): 0 The total was 55 The average is 5.5 Here are all the numbers less than the average: 1 2 3 4 5
Computers and Technology
1 answer:
olchik [2.2K]3 years ago
6 0

Here is code in java.

import java.util.*; // import package

class Main //  creating class

{

public static void main (String[] args) // main method

{

Scanner br=new Scanner(System.in); // scanner class for input

       int []a=new int[20]; // declaring array

       int count=0,x,j; // creating variable

       int sum =0;

       System.out.println("Enter a weight (0 to stop):");

       x=br.nextInt(); // taking input

while(x!=0) // iterating over the loop

       {

           a[count] = x;

           count++;

           System.out.println("Enter a weight (0 to stop):");

           x=br.nextInt();

}

       for( j=0;j<count;j++) // iterating over the loop

       {

       sum+=a[j];

       }

       double avg = sum/(double)count;

       System.out.println("The total is: "+sum);

       System.out.println("The average is: "+avg);

       System.out.println("Here are all the numbers less than the average: ");

     for( j=0;j<count;j++) //  // iterating over the loop

       {

           if(a[j]<avg)

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

       }

}

}

Explanation:

First create an object of "Scanner" class to read input from the user.

Create an array of size 20, which store the number given by user.Ask user

to give input and keep the count of number in the variable "count". If user

give input 0 then it will stop taking input.And then calculate sum of all the

input.It will calculate average by dividing the sum with count and print it.

It will compare the all elements of array with average value, if the element

is less than average, it will print that element.

Output:

Enter a weight (0 to stop):

1

Enter a weight (0 to stop):

2

Enter a weight (0 to stop):

3

Enter a weight (0 to stop):

4

Enter a weight (0 to stop):

5

Enter a weight (0 to stop):

6

Enter a weight (0 to stop):

7

Enter a weight (0 to stop):

8

Enter a weight (0 to stop):

9

Enter a weight (0 to stop):

10

Enter a weight (0 to stop):

0

The total is: 55

The average is: 5.5

Here are all the numbers less than the average:

1 2 3 4 5

You might be interested in
When creating a multi-dimensional array dynamically in C/C++ the Memory Manager will go to great pains to make sure the array is
yuradex [85]

Answer:

Here the statement is false.  

Explanation:

In C/C++, we can define multidimensional arrays in simple words as an array of arrays. Data in multidimensional arrays are stored in tabular form (in row-major order).  

General form of declaring N-dimensional arrays:  

data_type  array_name[size1][size2]....[sizeN];  

data_type: Type of data to be stored in the array.  

          Here data_type is valid C/C++ data type

array_name: Name of the array

size1, size2,... ,sizeN: Sizes of the dimensions.

Foe example:

Two dimensional array:

int two_d[10][20];  

Three dimensional array:

int three_d[10][20][30];

8 0
3 years ago
Outside of a C program, a file is identified by its ________while inside a C program, a file is identified by a(n) ________. fil
Alexxandr [17]

Answer: name, file stream object

Explanation:

4 0
2 years ago
Type of file containing instructions that tell your computer how to perform ___
julsineya [31]

Answer:

A)File

B)Native

C)Extension

D)File size

Explanation:

6 0
2 years ago
If one employee is assigned to a project and each project has only one employee working on it, there is a(n) ____ relationship b
Len [333]

Answer:

One-to-one is the answer because there is one project and one employee working on one project.

5 0
2 years ago
What does a head frame do​
coldgirl [10]

Answer:

The main objects of a head frame, or poppet head, are to support the winding pulley firmly and to guide the cage above the surface to the discharging stage. 

7 0
2 years ago
Other questions:
  • 1.6.6 Night out for codehs
    6·1 answer
  • I need to write a program that accepts eight int values representing student test scores from the user and then displays each of
    14·1 answer
  • Assume that sentence is a variable that has been associated with a string consisting of words separated by single space characte
    12·2 answers
  • A computer virus is a program that can copy itself and infect a computer without the permission of the owner. How do you think a
    9·1 answer
  • __________ are hosted on dedicated computers known as 'web servers'.​
    8·2 answers
  • In the textbox below, write an email that you, as an administrative assistant at Techno Inc., would write to request information
    7·1 answer
  • What is the difference between the Internet and the World Wide Web? Explain in your own words.
    13·2 answers
  • SNMP is a protocol used to query hosts, servers, and devices about performance or health status data. This protocol has long bee
    7·1 answer
  • What does a hanging indent look like?
    7·1 answer
  • What power points feature will you use to apply motion effects to different objects of a slide
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!