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]
4 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]4 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
Write code to print the location of any alphabetic character in the 2-character string passCode. Each alphabetic character detec
Flauer [41]

Answer:

//Program written in Java Programming Language

// Comments are used for explanatory purpose

import java.util.Scanner; //Scanner Library Imported

public class findloc { //Program Class Declared

public static void main (String [] args) {//Program Main Method

Scanner input = new Scanner(System.in);

string passCode; // Declare string passCode

passCode = Input.next();//Input Passcode

if(Character.isLetter(passCode.charAt(0)))//Check Alphabet Position

{

System.out.println("Alphabetic at 0");//Print Alphabet position is at 0

}

if(Character.isLetter(passCode.charAt(1))) //Check Alphabet Position

{

System.out.println("Alphabetic at 1");//Print Alphabet position is at 1

}

}

}

4 0
3 years ago
A(n) ________ software installation enables you to decide which features you want to install on the hard drive
Mazyrski [523]
<span>An element in the Excel window that displays the value or formula contained ... which you can specify the type of calculation you want to perform in an Excel formula are: ..... installs all the most commonly used files to your computer's hard drive. Full. A(n) ______ software installation enables you to decide which features you ...</span><span>
</span>
5 0
4 years ago
What reason best explains why complementary colors are important to web page design?
Brums [2.3K]

Complementary colors are important to web page design because they will inspire the visitor. For example, complementary colors make your website's text easier to red. They contrast with one another, so that they create a harmony for your page.

4 0
3 years ago
Read 2 more answers
Why are some constraints automatically applied by the software
balandron [24]

Answer:

Some constraint are automatically applied by the software while others must be entered manually because we have some shapes that just come with automatic constraint.

In instance can be given with square, this have all ot iits four sides equal with two set of parallel sides.

Explanation:

see Answer.

3 0
4 years ago
WILL GIVE BRAINLIEST
Fiesta28 [93]

Answer:

c

Explanation:

c

6 0
3 years ago
Read 2 more answers
Other questions:
  • How to hack the school system
    13·1 answer
  • What is a header and/or a footer? The bolded subtitle for each section or the footnote on any section Text inserted into the top
    11·1 answer
  • What is the gap between those with access to new technologies and those without called?
    13·2 answers
  • (TCO 4) What will the following program segment display? int funny = 7, serious = 15; funny = serious % 2; if (funny != 1) { fun
    14·2 answers
  • A small cluster of three countries (China, Malaysia, and Korea) are creating a reputation for this type of outsourcing. a. Farsh
    6·1 answer
  • What is the best way to set up the spreadsheet? List each expense in a row. List each income source in a column. List each expen
    15·2 answers
  • Jane is a full-time student on a somewhat limited budget, taking online classes, and she loves to play the latest video games. S
    14·1 answer
  • Inserting merge fields in the letter<br>steps required <br>plz ​
    11·2 answers
  • Research the significance of the UNIX core of macOS and write a few sentences describing your findings.
    8·1 answer
  • Carmen has met new people online that she enjoys talking to. One of these people has asked her to meet at the park in person and
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!