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
The code int *p; declares p to be a(n) ____ variable. new
Pavel [41]
Int* p; defines a pointer variable.
8 0
3 years ago
With ____ editing, Word automatically displays a Paste Options button near the pasted or moved text.
harina [27]
The answer is drag and drop. 
 With drag and drop editing, word automatically displays a paste option button near the pasted or moved text. 
8 0
3 years ago
A search engine finds bugs and system failures in your computer.<br><br> True or False?
scZoUnD [109]
It is false search engine are used for searching for something
6 0
2 years ago
Read 2 more answers
What file name would allow you to easily find and edit your document later in Word Online?
DIA [1.3K]
The first one “ jane_essay 2_24_21 “
6 0
2 years ago
Read 2 more answers
In database software, which option is the most appropriate menu choice or command to use if you want to change the format of the
sleet_krkn [62]

Answer:

I think it's d

Explanation:

             

4 0
2 years ago
Other questions:
  • Which of the following accurately completes this sentence? The Internet is ____.
    6·2 answers
  • Which social media post indicates your home may be unattended?
    10·1 answer
  • Which of the following combines something you know, such as a password, with something you are (a biometric device such as a fin
    13·1 answer
  • How to format the selected range of cells as u.s currency
    6·1 answer
  • Which composer below was not part of the classical period? <br> A. Beethoven B. Bach<br> C. Mozart
    6·1 answer
  • Graphic software task​
    7·1 answer
  • 4.11 lesson practice quizz need help on 2 and 3
    5·1 answer
  • What are the different alignment options available in Microsoft​
    11·2 answers
  • You want to send an email to members of your team working on a school project. In which field would you put the email addresses
    13·1 answer
  • write a recursive bool valued function containsvowel that accepts a string and returns true if the string contains a vowel
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!