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
olasank [31]
2 years ago
13

Write a program that reads an unspecified number of integers, determines how many positive and negative values have been read, a

nd computes the total and average of the input values (not counting zeros). Your program ends with the input 0. Display the average as a floating-point number.
Computers and Technology
2 answers:
Viktor [21]2 years ago
4 0

Answer:

The program to this question can be given as:

Program:

import java.util.*;

//import package for user input  

class Main     //define class

{

public static void main(String a[])  

//define main function

{

int positive_number=0,negative_number=0,count=0,num; //define variable

double total=0,avg=0;  

//creating Scanner class object.

Scanner ob = new Scanner(System.in);

System.out.println("Enter an integer, when done input 0: "); //message

num= ob.nextInt();

//taking input from user

if (num==0)  //check number equal to 0  

{  

System.out.println("No numbers are entered except 0"); //message

System.exit(1);

}

else

{

while (num!= 0)  

{    

   if (num> 0)

   {

positive_number++; // Increase positives

}

else

{

negative_number++; // Increase negatives

}

total=total+num; // Accumulate total

count++;    // Increase the count

num=ob.nextInt();

}

// Calculate the average

avg=total/count;

// Display values

System.out.println("The positive number is:"+positive_number);

System.out.println("The negatives number is:"+negative_number);

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

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

}

}

}

Output:

Enter an integer, when done input 0: 22

2

1

4

0

The positive number is:4

The negatives number is:0

total is:29.0

average is:7.25

Explanation:

In the above program firstly we import the package for user input then we define a class that is main in this class we define the main method in the main method we define variable. Then we create a scanner class object for user input. In the number variable, we take multiple inputs from the user and also check that the user does not insert 0 at the starting of the program. To check this we use the condition statement that is a number equal to 0 then it will terminate the program. In the else part we first declare the loop that checks that inserted number is positive and negative and in this, we calculate the total of the numbers and at the end of the loop, we calculate the average of the number and print all the values.

Jobisdone [24]2 years ago
3 0

Answer:

The code is given below in Java. Follow the code and question for better understanding.

Explanation:

import java.util.Scanner;

public class NumbersStats {

   public static void main(String[] args) {

       Scanner in = new Scanner(System.in);

       int pos = 0, neg = 0, count = 0, num;

       double total = 0;

       System.out.print("Enter an integer, the input ends if it is 0: ");

       while (true) {

           num = in.nextInt();

           if(num == 0) break;

           if(num > 0) {

               pos++;

           } else {

               neg++;

           }

           total += num;

           count++;

       }

       System.out.println("The number of positives is " + pos);

       System.out.println("The number of negatives is " + neg);

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

       System.out.println("The average is " + (total/count));

   }

}

You might be interested in
What are the two ways to use the help menu
neonofarm [45]
What help menu are you talking about?
6 0
3 years ago
Read 2 more answers
Pre-Test
ozzi

Some of the options in this question are not correct; here is the correct and complete question:

In order for a fictionalized story to be based on real events, the author should include

A. Characters with strong feelings

B. Historical material

C. A narrator

D. Dialogue​

The correct answer is B. Historical material

Explanation:

Stories, novels, and poems are said to be based on real events if these include or are inspired by real people, settings, or historical events. This includes using any historical material and adapting it to create a story. For example, the play "The Tragedy of Julius Caesar" written by Shakespeare is a play based on real events as it includes real characters such as Julius Caesar and some of the events in it are based on historical events.

According to this, the element that is necessary to make a story to be based on real events is historical material. Also, others such as a narrator, dialogue, or characters with strong feelings can be found in most stories including those that are completely fictionalized.

3 0
3 years ago
Many web browsers include _____ tools to make it easier for designers to locate the source of a style that has been applied to a
larisa86 [58]

Answer:

Developer tools.

Explanation:

The main aim of developer tools to loading the HTML(hypertext markup language), CSS and JavaScript it describes how much time takes the page to load in the web browser.

The developer tools make the task easier for the designer to locate the source code which is applied to a specific page element.​We can easily see the source code of the particular website by using the Developer tools. So it makes the task easier for programmers and developers.

4 0
3 years ago
2. What is software conflict?<br>​
Morgarella [4.7K]

Answer:

A problem that occurs when two programs cannot run in the same computer at the same time. It is generally due to a programming bug and typically manifests when two programs compete for the same resource (memory, peripheral device, register, etc.).

Hope it helps out!

Explanation:

3 0
2 years ago
What data type stores images and audio visual clips???
nevsk [136]
Jpg is what I use for my audio and images
3 0
3 years ago
Other questions:
  • What type of restrictions may be placed on your license?
    7·1 answer
  • What is the best free game designing program for windows
    5·1 answer
  • Why is it more secure to require a user to press ctrl+alt+delete to log on rather than displaying the windows welcome screen?
    15·1 answer
  • What may happen if a large number of computer users are attempting to access a web site at the same time that you are?
    14·1 answer
  • What is the difference between Google and a subject directory like Yahoo Directory or Infomine?
    14·2 answers
  • Using Amdahl’s Law, calculate the speedup gain of an application that has a 60 percent parallel component for (a) two processing
    11·1 answer
  • Suppose that a system uses 32-bit memory words and its memory is built from 16 1M × 16 RAM chips. How large, in words, is the me
    11·1 answer
  • Windows workstations all have elements of server software built-in. What are these elements, and why is the Windows Professional
    9·1 answer
  • Which country was the first in the world to launch a mass media campaign in response to population growth?
    14·1 answer
  • To determine what to study one Should first
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!