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
Gnom [1K]
2 years ago
6

Write a program that asks the user to enter a series of numbers separated by commas. Here is an example of valid input: 7,9,10,2

,18,6 The program should calculate and display the sum of all the numbers.

Computers and Technology
1 answer:
alex41 [277]2 years ago
8 0

Answer:

Here is the JAVA program. Let me know if you need the program in some other programming language.

import java.util.Scanner; // used for taking input from user

public class Main{ //Main class

public static void main(String[] args) {//start of main() function body

  Scanner scan = new Scanner(System.in); // creates a Scanner type object

   String input; // stores input series

    int sum = 0; //stores the sum of the series

    System.out.println("Enter a series of numbers separated by commas: "); //prompts user to enter a series of numbers separated by comma

     input = scan.nextLine(); //reads entire input series

     String[] numbers = input.split("[, ]"); //breaks the input series based on delimiter i.e. comma and stores the split sub strings (numbers) into the numbers array

   for (int i = 0; i < numbers.length; i++) { //loops through each element of numbers array until the length of the numbers reaches

          sum += Integer.parseInt(numbers[i]); } // parses the each String element of numbers array as a signed decimal integer object and takes the sum of all the integer objects

     System.out.println("Sum of all the numbers: " + sum);  } } //displays the sum of all the numbers

Explanation:

The program prompts the user to enter a series separated by commas.

Then split() method is used to split or break the series of numbers which are in String form, into sub strings based on comma (,) . This means the series is split into separate numbers. These are stored in numbers[] array.

Next the for loop iterate through each sub string i.e. each number of the series, converts each String type decimal number to integer using Integer.parseInt and computes the sum of all these integers. The last print statement displays the sum of all numbers in series.  

If the input is 7,9,10,2,18,6

Then the output is: 7+9+10+2+18+6

sum = 52

The program and its output is attached.

You might be interested in
If I make a Zoom Meeting, would you join it?
boyakko [2]

Most likely, yeah lol.

3 0
3 years ago
Read 2 more answers
What job does a front-end developer perform?
alina1380 [7]

Answer:

They manage making websit/es beautiful. Basically how brainly is setup? The layout is nice? Front end developers are responsible for why webpages look pretty or nicely done. <em>fun fact, my dream job is a front end developer!</em>

5 0
2 years ago
Create and apply a CSS class named YellowBackground that selects a yellow background. Apply the class to your HTML file’s body t
RSB [31]

<!DOCTYPE html>

<html>

<head>

 <title>Page Title</title>

</head>

<body class="YellowBackground">

 <style>

    .YellowBackground {

        background-color:yellow;

    }

</style>

</body>

</html>


Like this?

7 0
3 years ago
What is the nearest inhabited area to the amazon rainforest
TEA [102]
There are inhabited areas INSIDE the Amazon Rainforest. Many primitive tribes with little to no contact of the outside world live in remote areas of the rainforest, but the closest major city to the rainforest (also inside) is Manaus, Brazil.
4 0
3 years ago
When installing a SATA hard drive, is it true or false that you need to move the jumpers on the back of the drive to instruct th
antiseptic1488 [7]

Answer:

This is false.

Explanation:

SATA drives do not have jumpers, because they don't use the master/slave feature. They are connected to the motherboard, and they are ready to work.

The master/slave feature was used by IDE hard drives.15 years ago, most motherboards didn't have too many IDE slots to place more than 1 or 2 HDDs, the IDE cable allowed you to connect 2 drives to 1 cable, greatly increasing your computer's storage space.

It was recommended to set as master the drive connected directly to the motherboard, and the other one as slave.

7 0
2 years ago
Other questions:
  • The ______ identifies the path for the currently open folder
    8·2 answers
  • Why is a networked system a benefit?
    7·1 answer
  • Andrea needs to format the legend on her chart. She clicks on the chart to select it. Which of the
    13·1 answer
  • A Windows application which demands a lot of raw processing power to execute repetitive complex calculations is a good candidate
    9·1 answer
  • What is a computer dedicated to a single function, such as a calculator or computer game? A. TabletB. PDAC.ApplianceD. Minicompu
    6·1 answer
  • L00000000000000000000000000000000000000000000000000000000l they b00ty tickled
    6·2 answers
  • Why is an increase in tax rate not necessarily increase government revenue​
    10·1 answer
  • Which path needs to be followed to change the currency settings of Windows Operating System?
    14·1 answer
  • What is the role of computer in education sector?​
    13·1 answer
  • Budgeting for a Computer
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!