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
Ryan is looking to buy a new HDTV set. He knows from friends that LCD set screens reflect less light than plasma set screens, bu
lbvjy [14]

Answer: Cognitive

Explanation:

 According to the question, the Ryan shows cognitive attitude towards the HDTV. The cognitive component basically refers to the three main components that are:

  • Thoughts
  • Beliefs
  • Attributes

The cognitive component is one of the type of attitude which basically consist of various types of thoughts, knowledge and the beliefs towards the any type of object. It is one of the belief and opinion of the attitude.  

3 0
2 years ago
A _____ object is the instance of a class that receives a request from another object. Select one: a. client b. server c. contra
creativ13 [48]

Answer:

b. server

Explanation:

A server serves responses to requests from client objects.

5 0
3 years ago
A technician is troubleshooting a Windows system in which an application works properly when the computer is booted in Safe Mode
sweet-ann [11.9K]

Answer:

yoooo nba BAD BAD

Explanation:

3 0
2 years ago
Im Gonna Give Brainly a Second Chance<br><br> Everybody deserves a second chance
Nady [450]

Answer:

ok I know it's not for me but for who?

Explanation:

Just asking. And yes everyone deserves a second chance. Even liars?

please don't take my question wrongly have an above average day!

7 0
3 years ago
Read 2 more answers
"in troubleshooting a boot problem, what is the advantage of restoring all uefi/bios settings to their default values?"
Alex17521 [72]
When this case would appear, one thing that I would do personally would first, go to the settings, in then, after having this done, I would then "scroll down" to where ti would say "restore (uefi/bios) files, and from there, you would get every value that would would have from the beginning in your chip.

And also, what is truly unique would be the fact that you would be able to choose the "restore point" that you would like for it to appear.
3 0
2 years ago
Other questions:
  • Which functions are performed by server-side code??​
    10·1 answer
  • What is the best overall approach to education and career development for IT professionals?
    14·2 answers
  • You are configuring IP settings on a new network. For the external interfaces, you decide to obtain registered IP addresses from
    5·1 answer
  • Nested if-else structures can contain many blocks of code. How many of those blocks of code might be executed?
    14·1 answer
  • A coworker asks your opinion about how to minimize ActiveX attacks while she browses the Internet using Internet Explorer. The c
    14·1 answer
  • Ann wants to save her presentation so she can work on it later. Which device on her computer can store this data long term?
    14·1 answer
  • Kellyn needs to move Slide 8 of his presentation up so that it becomes Slide 6. What best describes how he can do this using the
    11·2 answers
  • Which of these are characteristics of a Python data type? Check all that apply.
    11·1 answer
  • How do we produce quality work in editing audio?
    7·1 answer
  • Question 1 (True/False Worth 3 points)
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!