- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How do you find the sum of all the numbers in a java array
Following program print the sum of the all the numbers in an array.
Example
public class Tester { public static void main(String[] args) { int[] dataArray = {1, 2, 3, 4}; int sum = 0; for(int i: dataArray) { sum += i; } System.out.println(sum); } }
Output
10
Advertisements