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
patriot [66]
3 years ago
14

Write a program, NumberStatistics.java, that reads an unspecified number of integers. The program ends with the input 0. The pro

gram determines the average of all positive values, the average of all negative values, the average of all the values, the maximum value, and the minimum value.
Computers and Technology
1 answer:
Lerok [7]3 years ago
6 0

Answer:

Following are the program, which can be below:

import java.util.*; //defining header file

public class NumberStatistics  //defining class NumberStatistics

{

public static void main(String[] arc) //defining main method

{

int total_number=0,max_val=0,min_val=0,neg_val=0,pos_val=0,neg_count=0,pos_count=0,x; //defining variables

Scanner ox= new Scanner(System.in); //creating Scanner class Object

System.out.println("Enter positive and negative value with sign and when complete inter 0:"); //print message  

x= ox.nextInt(); //input value from user

while(x!=0) //defining loop to check input value is 0

{

total_number++; // increment value

if(total_number == 1)  //defining conditional statement to check minimum and maximum value

{

max_val = x; //assign value in max  

min_val = x;//assign value in min

}

else  //defining else block

{

if(max_val < x) //check maximum value

{

max_val = x; //assign maximum value

}

if(min_val > x) //check minimum value

{

min_val = x; //assign minimum value

}

}

if(x > 0) //input values  

{

pos_count++; //count positive value

pos_val+=x; // add positive values

}

else  

{

neg_count++;//count negative value

neg_val+=x; // add negative values

}

x = ox.nextInt(); //input values

}

// defining conditionl statement

if(total_number != 0)  // defining if block to print all value

{

System.out.println("positive value average= "+(pos_val/(double)pos_count));

System.out.println("negative values Average= "+(neg_val/(double)neg_count));

System.out.println("all values average= "+(pos_val+neg_val)/(double)total_number);

System.out.println("maximum value = "+max_val+"\n"+" minimum value = "+min_val);

}

else  

{

System.out.println("no positive values found");

System.out.println("no negative values found");

}

}

}

Output:

Enter positive and negative value with sign and when complete inter 0:

12

8

04

22

-22

-5

9

0

positive value average= 11.0

negative values Average= -13.5

all values average= 4.0

maximum value = 22

minimum value = -22

Explanation:

The Description of the above java program can be described as follows:

  • In the above code first we import the package for user input, then defines the variable "total_number,max_val,min_val,neg_val,pos_val,neg_count, pos_count,x" to store the value prints its value.
  • In the next step, a scanner class object is created for user input and defines a while loop, that checks input value isn't equal to 0, inside the loop a conditional statement defines that cont and calculates all positive, negative, and all values addition.
  • At the another conditional statement is defines, that prints all value average, and also prints maximum, minimum value.
You might be interested in
Why won't my ads load brainly? Is anyone else having this problem? Brainly company or whoever you are that is running this websi
djverab [1.8K]

No I have not had that do that to me before It has always loaded my ads and sent me right back to the answer

7 0
3 years ago
Read 2 more answers
The batteries on electric vehicles are recharged using electricity from either a wall socket or dedicated charging unit.
yuradex [85]

Answer:

true

Explanation:

7 0
2 years ago
2. In many jurisdictions a small deposit is added to containers to encourage people to recycle them. In one particular jurisdict
RUDIKE [14]

Answer:

Here is the Python program:

small_container = int(input("Enter the number of small containers you recycled?"))

large_container = int(input("Enter the number of large containers you recycled?"))

refund = (small_container * 0.10) + (large_container * 0.25)

print("The total refund for returning the containers is $" + "{0:.2f}".format(float(refund)))

Explanation:

The program first prompts the user to enter the number of small containers. The input value is stored in an integer type variable small_container. The input is basically an integer value.

The program then prompts the user to enter the number of large containers. The input value is stored in an integer type variable large_container. The input is basically an integer value.

refund = (small_container * 0.10) + (large_container * 0.25)  This statement computers the refund that will be recieved for returning the small and larger containers. The small containers holding one litre or less have a $0.10 deposit so the number of small containers is multiplied by 0.10. The large containers holding more than one litre have a $0.25 deposit so the number of large containers is multiplied by 0.25. Now both of these calculated deposits of containers of each side are added to return the refund that will be received for returning these containers. This whole computation is stored in refund variable.

print("The total refund for returning the containers is $" + "{0:.2f}".format(float(refund))) This print statement displays the refund in the format given in the question. The output includes a $ sign and displays exactly two decimal places by using {0:.2f} where .2f means 2 decimal places after the decimal point. Then the output is represented in floating point number using. format(float) is used to specify the output type as float to display a floating point refund value up to 2 decimal places.

5 0
3 years ago
When an application contains an array and you want to use every element of the array in some task, it is common to perform loops
Elodia [21]

Answer:

 Option A(True) is the correct answer for the above question.

Explanation:

  • An array is used for the collection variables which is of the same type and uses memory in continuous Passion for the storage.
  • When any user wants to use the array then he needs to declare the size and type of the array because array holds the same type of data.
  • For example, int a[5] is an array of integer variable whose name is 'a' and the size is 5 in c language.
  • Anyone can use the array with the help of the index value of the array. The starting index value is 0 and the ending index value is (size-1) for any array.
  • The user can use it by the help of loop, in which the loop variable refers to the index of the array and it starts from 0 and ends in the (size of the array-1).
  • It is because the loop executes the same line multiple times.
  • The above statement also wants to state, which is defined as above. Hence the above statement is true which is referred by option A. Hence option A is the correct answer.
7 0
3 years ago
A startup is developing a new web browser with a focus on accessibility for visually impaired users. The startup founder is cons
gavmur [86]

Answer:

A license that allows developers to change and share the source

code of the licensed software

Explanation:

i learned this, btw brainly stop removing my answers

7 0
2 years ago
Other questions:
  • How to copy music from windows media player to pc?
    13·1 answer
  • The this reference . a) can be used implicitly b) must be used implicitly c) must not be used implicitly d) must not be used 25)
    11·1 answer
  • A _____ captures the pattern in a _____ and sends it to the computer, where special software translates the _____ into meaningfu
    8·1 answer
  • A business wants to centralize its administrative tasks. At the same time, it wants the existing systems to manage and sustain t
    5·1 answer
  • 15) the following statement describes government depository librearies , except:
    12·1 answer
  • Describe the functions of ALU, resisters, CU, BIU, Cache and FPU.
    7·1 answer
  • A student that earns a well qualified score on an ap exam would receive a ___
    13·1 answer
  • What is the difference between i++ and ++ii?
    6·1 answer
  • What is a geam in the ggplot2 system?
    5·1 answer
  • What should you do if your computer is running slower
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!