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

Write a program with a loop that lets the user enter a series of positive integers. The user should enter −1 to signal the end o

f the series. The program should count all the numbers entered, compute the running total of the numbers and displays their count, total and average. Display average to decimal places.
Computers and Technology
1 answer:
Fiesta28 [93]2 years ago
5 0

Answer:

import java.util.Scanner;

public class num2 {

   public static void main(String[] args) {

       Scanner in = new Scanner(System.in);

       int count =0;

       int total = 0;

       System.out.println("Enter the numbers");

       int num = in.nextInt();

       while(num!=-1){

           total = total+num;

           count++;

           System.out.println("Enter the next number");

           num = in.nextInt();

       }

//Compute the average

       double average = (double) total/count;

//Outputs

       System.out.println("Total count of numbers entered "+(count));

       System.out.println("Sum of the numbers "+total);

       System.out.printf("Average is %.2f ",average);

   }

}

Explanation:

  • Using java programming language
  • Import scanner class to receive user input
  • declare variables count and total and initialize to zero
  • Prompt user to enter numbers
  • Use a while statement with the condition while(num!=-1)
  • Within the while body keep prompting user to enter a number, increase count and update total
  • when -1 is entered the loop breaks and average is calculated
  • Use printf() method to print average to 2 decimal places.
You might be interested in
Please NEED HELP ASAP WILL MARK BRAINLIEST ONLY #8
ValentinkaMS [17]

Answer:

I think its A

Explanation:

6 0
2 years ago
Need to know? Anyone feel like helping me not fail
8_murik_8 [283]
I’m not sure but i think it might be design
4 0
2 years ago
Write a function with this prototype:
sp2606 [1]

Answer:

Following are the code to this question:

#include <iostream> //defining header file  

using namespace std;

void numbers(ostream &outs, const string& prefix, unsigned int levels); // method declaration

void numbers(ostream &outs, const string& prefix, unsigned int levels) //defining method number

{

string s; //defining string variable

if(levels == 0) //defining condition statement that check levels value is equal to 0

{

outs << prefix << endl;  //use value

}

else //define else part

{

for(char c = '1'; c <= '9'; c++) //define loop that calls numbers method

{

s = prefix + c + '.'; // holding value in s variable  

numbers(outs, s, levels-1); //call method numbers

}

}

}

int main() //defining main method

{

numbers(cout, "THERBLIG", 2); //call method numbers method that accepts value

return 0;

}

Output:

please find the attachment.

Explanation:

Program description:

  • In the given program, a method number is declared, that accepts three arguments in its parameter that are "outs, prefix, levels", and all the variable uses the address operator to hold its value.
  • Inside the method a conditional statement is used in which string variable s and a conditional statement is used, in if the block it checks level variable value is equal to 0. if it is false it will go to else block that uses the loop to call method.
  • In the main method we call the number method and pass the value in its parameter.  

5 0
3 years ago
Python;
riadik2000 [5.3K]

a = int(input("Class A tickets sold: "))

b = int(input("Class B tickets sold: "))

c = int(input("Class C tickets sold: "))

print("Total income generated: $"+str((a*20)+(b*15)+(c*10)))

I hope this helps!

4 0
2 years ago
What does UDP stand for?
sleet_krkn [62]
User Datagram Protocol
3 0
3 years ago
Read 2 more answers
Other questions:
  • If you are planning to carry a large balance on your credit card, which of the following credit card features should you look fo
    7·2 answers
  • Ports on the motherboard can be disabled or enabled in ____ setup. RAM Firmware Northbridge BIOS
    8·1 answer
  • Im trying to learn c# for unity does anyone know any good sources
    10·1 answer
  • What defines "print media"? It is media that includes words and text rather than video, such as many blogs. It is media that is
    8·1 answer
  • Instead of terminating the series, the producers decided to extend it for an additional season. In the sentence above, which of
    13·1 answer
  • If you want Nud3s add me on sc Kermit4lyfe1
    11·2 answers
  • 10010 - 1011 binary subtraction​
    5·1 answer
  • Why do certain words change color in Python?
    6·1 answer
  • What is a common translator?​
    9·1 answer
  • What are the four different orchestral instrument families?
    6·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!