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
Kay [80]
2 years ago
7

How to add up multiple user inputs for example: If i ask the user How many numbers do you want to add? they say 5 then i out put

Enter 5 numbers: how can i get it to add up those 5 numbers that were input.In JAVA
Computers and Technology
1 answer:
Morgarella [4.7K]2 years ago
6 0

Answer:

import java.util.Scanner;

class Main {

 public static void main(String[] args) {

   Scanner scanner = new Scanner(System.in);

   System.out.println("How many numbers do you want to add?");

   int numberOfNumbers = scanner.nextInt();

   int arrayNumbers[] = new int[numberOfNumbers];

   System.out.println("Enter " + numberOfNumbers + " numbers:\n");

   for(int i = 0; i < numberOfNumbers; i++){

     int addToArray = scanner.nextInt();

     arrayNumbers[i] = addToArray;

   }

   int sum = 0;

   for(int j = 0; j < arrayNumbers.length; j++){

     sum+=arrayNumbers[j];

   }

   System.out.println("Sum: " + sum);

 }

}

Explanation:

You might be interested in
Explain each kind of pointer and for what it is appropriate
ycow [4]

Answer:

Explanation:

A pointer is nothing but a memory location where data is stored. A pointer is used to access the memory location. There are various types of pointers such as a null pointer, wild pointer, void pointer and other types of pointers. ... When you want to deal different variable data type, you can use a typecast void pointer.

8 0
3 years ago
Read 2 more answers
________ enables advertisers to display more relevant ads based on user's search and browsing history. FIP NORA A Web bug An int
Arturiano [62]

Answer:

Behavioural targeting

Explanation:

Behavioural targeting is the method that enables advertisers to display more relevant ads based on user's search and browsing history. This is an online targeting technique that collects information from a particular user. This information comes from the person's browsing history. The information that comes from the browsing history enable advertisers to display specific targeted ads that would most appeal to the person in question.

7 0
3 years ago
Jack is writing a paragraph for a school assignment. He proofreads his paper and notices that he used the word, "then" many time
Lynna [10]

He should use a Thesaurus.

5 0
3 years ago
Read 2 more answers
(Game Design) Creating and manipulating data structures is one of the primary functions of a development environment.
Galina-37 [17]

true i believe im not for sure

7 0
3 years ago
Read 2 more answers
Which best describes an advantage of creating a contact group?
Lapatulllka [165]
More than one contact can be added to the group at a time.
8 0
3 years ago
Other questions:
  • A style manual can be described as
    11·2 answers
  • 2. Suppose you want to write a method that prints a heading on a new output page, along with a page number that is 1 in the firs
    15·1 answer
  • 3. Find the product of (a² +3a+5) x (a+7)​
    7·1 answer
  • Discuss the importance of employee security awareness training. What innovative ways should company’s implement security trainin
    14·1 answer
  • HELP PLEASE I WILL GIVE YOU 15 POINTS!
    8·1 answer
  • Devices which are used to receive data from central processing unit are classified as
    11·1 answer
  • QUESTIONS Which of the following use cases are suitable for compute-optimized cloud offering? ОА. None of the listed O B. Highly
    12·1 answer
  • If you said the bottom margin, you are talking about what?
    13·2 answers
  • Who wants to join my Among us?<br><br><br>Code: EDQKNF <br><br><br>&lt;3333​
    9·2 answers
  • Why does my smoke detector keep beeping even after i change the battery?.
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!