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
What is returned by the code: range (5, 100, 25) ?
Nataly [62]
You would have to add them up need more info on the returned video
6 0
3 years ago
Read 2 more answers
Consider the following program segment. ifstream inFile; //Line 1 int x, y; //Line 2 ... //Line 3 inFile &gt;&gt; x &gt;&gt; y;
MrMuchimi

Answer:

inFile.open("progdata.dat");

Explanation:

This command opens the file which is passed to it as an argument. We are quite used to the C++'s cin and cout functions contained in iostream library for reading and writing data, however, when working will real-life stuff, we find ourselves working with huge data saved as separate files and require our programs to read them, manipulate them and possibly write back to the files... The first operation usually carried out before a file can be read or written to is open

6 0
3 years ago
A customer in Lowe's needs help. Matt works in shipping and receiving. It isn't Matt job to work with the customer, but he knows
klio [65]

Answer:

40

Explanation:

hhhhhjjjj

5 0
2 years ago
Read 2 more answers
Which of the given original work is protected by the copyright law?
Mila [183]

Answer:i would love to help but are there any answer choices?

Explanation: please provide answer choices for an accurate answer

6 0
3 years ago
1 There are several applications to assist you to surf through the internet, mention
prohojiy [21]
Email
Web browsing
Peer-to-peer services
3 0
3 years ago
Other questions:
  • Show what this program prints. Be exact and complete. Can you explain the behavior of each print statement? 1 2 3 4 5 6 7 public
    12·1 answer
  • Mike is reading about machine-dependent programming languages. Which languages are machine-dependent programming languages?
    11·1 answer
  • 13. The Save As command is useful if you want to copy an open document and
    7·2 answers
  • Carly is part of a community of developers. In her free time, she works on code to improve this open-source operating system. Th
    11·1 answer
  • How do you change your age on here? I accidentally put that i was 15 but i am only 13. How do I change this?
    12·1 answer
  • An access control system that grants users only those rights necessary for them to perform their work is operating on which secu
    6·1 answer
  • _____ creates a border or space that separates information.
    14·1 answer
  • What did major networks do to combat audience erosion in the 1990s?
    15·1 answer
  • If you want to transfer information transform STM to LTM, it is essential that you make the information ______________________.
    9·1 answer
  • List all the steps used to search for 25 in the sequence given below. Use both (a) linear search and (b) binary search. 2, 7, 13
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!