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 button is used for paragraph alignment on Microsoft 2016?
Margarita [4]
Just click the buttons on the Paragraph tab on Home.
6 0
3 years ago
HTTP is made to facilitate which kind of communication?
vlada-n [284]

Answer:

Computer to computer.

Explanation:

HTTP facilitates the connection between websites, so the answer is computer to computer.

5 0
2 years ago
For this portion of the lab you will design the solution so that you perform some conditional tests. For this lab: 1. You will v
PIT_PIT [208]

Answer:

#Prompt the user to enter the miles.

Miles = float(input('Enter the miles to convert into kilometer: '))

#Check the miles.

if Miles >= 0 :

   #Convert the miles to kilometers.

   Miles_To_km = Miles*1.6

   #Display the result.

   print (Miles, "miles equivalent to", Miles_To_km, "kilometer.")

   #Prompt the user to enter the gallons.

   Gallon = float(input('Enter the gallons to convert into liter: '))

   #Check the validity of the Gallons entered.

   if Gallon >= 0:

       #Convert gallons into liters.

       Gal_To_Lit = Gallon*3.9

       #Display the result.

       print (Gallon, "gallons equivalent to", Gal_To_Lit, "liters.")

       #Prompt the user to enter the pounds.

       Pound = float(input('Enter the pounds to convert into kilograms: '))

       #Check the validity of the Pounds entered.

       if Pound >= 0:

           #Convert pounds into kilograms.

           Pounds_To_Kg = Pound*0.45

           #Display the result.

           print (Pound, "pounds equivalent to", Pounds_To_Kg, "kilograms.")

           #Prompt the user to enter the temperature in Fahrenheit.

           f = float(input('Enter the temperature in Fahrenheit: '))

           #Check the value to be not greater than 1000.

           if f < 1000:

               #Convert Fahrenheit into celsius.

               F_To_C = (f -32)*5/9

               #Display the result.

               print (f, "Fahrenheit equivalent to", F_To_C, "celsius.")

           #Otherwise.

           else:

               

               #Display the error message.

               print ("Invalid temperature (greater than 1000) !!!")

       else:

           #Display the error message.

           print ("Pounds cannot be negative !!!")

   else:

           #Display the error message.

           print ("Gallons cannot be negative !!!")

else:

   #Display the error message.

   print ("Miles cannot be negative !!!")

Explanation:

4 0
3 years ago
P1 has a clock rate of 4 GHz, average CPI of 0.9, and requires the execution of 5.0E9 instructions.P2 has a clock rate of 3 GHz,
nadezda [96]

Answer:

Following is attached the solution for all parts. I hope it will help you!

Explanation:

7 0
3 years ago
General purpose application include all the following except
Citrus2011 [14]

Answer: Web authoring

Explanation:

Here's the complete question:

General-purpose applications include all of the following except:

Select one:

a. web authoring

b. word processors

c. spreadsheets

d. database management systems

General purpose application refers to the application which can be used for different tasks. Examples of General purpose application are Spreadsheet, Word processors, Presentation software, Database management system etc.

The general purpose applications are quite different from the specialized application which focuses on a particular discipline. Therefore, the option that isn't a general purpose application is the web authoring.

8 0
3 years ago
Other questions:
  • Which best describes IMEI?
    7·1 answer
  • How many slides should a presentation include?
    11·2 answers
  • A popular Voice over Internet Protocol (VoIP) service is ________.
    12·1 answer
  • Can anyone please help with this programming code in python num= 7 if num &gt; 3: print(“3”) if num &lt; 5: print(“5”) if num ==
    6·1 answer
  • Susan is working with an IT company. She has been asked to make sure that all of the functions in the company are in place and p
    12·1 answer
  • What kinds of dogs are there
    9·2 answers
  • Easy coding question, please help.
    13·1 answer
  • Could someone please help?​
    10·1 answer
  • There have not been any changes to instruments or music in the last 50 years. The technology in music is still the same.
    12·1 answer
  • Attackers will sometimes put malware on USB drives and leave them in parking lots
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!