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]
3 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]3 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
You work as an IT Technician for uCertify Inc. David, a user, has recently purchased a laptop computer. He is now complaining th
olganol [36]

Answer:

Check the hardware switch on the wireless antenna card that activates the service.

Explanation:

The person works for uCertify Inc as an IT Technician. David, a regular, has just buy a laptop. He still says that he will not link to a wireless connection, although his laptop seems to have an inner wireless app. So, by checking the hardware switch on the wireless antenna card that activates the service, that person resolves the issue.

7 0
3 years ago
Create a flowchart that assigns a counselor to a student.
Nataly [62]
Please Help! Unit 6: Lesson 1 - Coding Activity 2
Instructions: Hemachandra numbers (more commonly known as Fibonacci numbers) are found by starting with two numbers then finding the next number by adding the previous two numbers together. The most common starting numbers are 0 and 1 giving the numbers 0, 1, 1, 2, 3, 5...
The main method from this class contains code which is intended to fill an array of length 10 with these Hemachandra numbers, then print the value of the number in the array at the index entered by the user. For example if the user inputs 3 then the program should output 2, while if the user inputs 6 then the program should output 8. Debug this code so it works as intended.

The Code Given:

import java.util.Scanner;

public class U6_L1_Activity_Two{
public static void main(String[] args){
int[h] = new int[10];
0 = h[0];
1 = h[1];
h[2] = h[0] + h[1];
h[3] = h[1] + h[2];
h[4] = h[2] + h[3];
h[5] = h[3] + h[4];
h[6] = h[4] + h[5];
h[7] = h[5] + h[6];
h[8] = h[6] + h[7]
h[9] = h[7] + h[8];
h[10] = h[8] + h[9];
Scanner scan = new Scanner(System.in);
int i = scan.nextInt();
if (i >= 0 && i < 10)
System.out.println(h(i));
}
}
4 0
3 years ago
Read 2 more answers
What is meant by hacking in internet ?ASAP PLEASEEEE​
yanalaym [24]
Im not sure if you mean in or by but heres my answer: Basically to attempt to exploit a private network, control over computers, viruses and such.
8 0
3 years ago
Assignment 1 silly sentences
ololo11 [35]

Answer:

Sally sells sea shells by the sea shore

Explanation:

3 0
3 years ago
How many 2/8 pound patties can she make from 7/8 of a pound of hamburger
Juli2301 [7.4K]

Answer:

3/8

Explanation:

Because 2 can't go into 7, the next best thing is 6, so 2x3 is 6 with 1/8 left over~~~~~hope this helps :) pls brainlist

7 0
3 years ago
Other questions:
  • Naseer has inserted an image into his document but needs the image to appear on its own line.
    14·2 answers
  • Manny has created more than one hundred bookmarks. When he looks at the menu, he has to scroll through a very long list of bookm
    15·1 answer
  • Which of the following is used to allocate memory for the instance variables of an object of a class?1. the reserved word public
    6·1 answer
  • Every modern nation has a Central Bank. Which of the following is the Central Bank for these United States?
    14·2 answers
  • Question 10
    14·1 answer
  • Question 1 of 10 Chase lives in Oregon but works for a company that is located in Florida. What business trend is this an exampl
    11·2 answers
  • What is the difference between a crosstab query and a subquery?
    11·2 answers
  • Thinking about the career cluster, "Information Technology", which of these careers would typically NOT be included? (Choose thr
    10·2 answers
  • What type is the combination of an integer and a string
    13·1 answer
  • You can change the ____ or position of text within a document's margins.
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!