2023-02-26

sum of array elements in java using while loop

rev2023.1.17.43168. iOS Because of that, you should use in your loop condition. After the termination of the loop, print the value of the sum. Print the average. Java Array - While Loop. This . System.out.println("Sum of array elements is: " + sum); And calculating the sum of all even numbers and printing them. If the array is of type double, then the stream will be of java.util.stream.DoubleStream Above code can also be reduced to a single line as below. ("#deftext"). Now, we will learn about the reduce() method that will be used for calculating the sum of the array elements. hiring MATLAB in Orlando, Florida, United States. int sum = (int)StatUtils.sum(array); } But now, we will use the reduce() method to calculate the sum instead pf for a loop as shown below. Ilias is a software developer turned online entrepreneur. int element = array[loopCounter]; sum += element; The reduced method for arrays in javascript helps us specify a function called reducer function that gets called for each of the elements of an array for which we are calling that function. Write a Program Detab That Replaces Tabs in the Input with the Proper Number of Blanks to Space to the Next Tab Stop. In this tutorial, we will learn how to use Java While Loop to iterate over the elements of Java Array. Method 4: Using reduction operation on stream This method also uses a stream to find the sum of array elements. Call a method that will calculate the sum and average of all the elements in an array. QGIS: Aligning elements in the second column in the legend, Toggle some bits and get an actual square. 3 Disparate Interactions: An Algorithm-in-the-Loop Analysis of Fairness in groups are particularly large because (given that r - cis the . Getting the sum using a for loop implies that you should: Lets take a look at the code snippet that follows: This was an example of how to get the sum of the numbers in an array using a for loop in Java. To find the sum of elements of an array. The below program demonstrates how to accept the elements of an array and calculate the sum of all the elements in the array using each loop. } In this article, we will learn about how sum of array elements can be calculated using the standard old way of for loop and then by the new optimized, efficient and convenient way of reducing () method along with its syntax and examples. Hi Andren, thank you. Ask the user to initialize the array elements. The comment form collects your name, email and content to allow us keep track of the comments placed on the website. Create an array of numbers, in the example int values. Program 1. Invincible Publishers; News; Invincible Activities; sum of array elements in java using while loop In this program, we need to calculate the sum of all the elements of an array. System.out.println("Sum of array elements is: " + sum); This is crucial to take note of, when you're doing this: because, as you defined it, i is not 1, which means that your assign the 2nd index, index 1 to the return value of input.nextInt(). What does and doesn't count as "mitigating" a time oracle's curse? Java program to calculate the sum of N numbers using arrays, recursion, static method, using while loop. Card trick: guessing the suit if you see the remaining three cards (important is that you can't move or turn the cards). Let us begin by studying its syntax. Output of this program is the same as the previous one. sum += element; // add the elements in stream using reduction JCGs (Java Code Geeks) is an independent online community focused on creating the ultimate Java to Java developers resource center; targeted at the technical architect, technical team lead (senior developer), project manager and junior developers alike. Create a for statement, with an int variable from 0 up to the length of the array, incremented by one each time in the loop. You can use a similar approach to sum the elements of a multidimensional array of any size. 528), Microsoft Azure joins Collectives on Stack Overflow. } Control Flow With Loops } Can state or city police officers enforce the FCC regulations? From javadocs. Make sure your condition allows for iteration over all elements in the numbers array and check your calculation of sum!". I can't figure out how to do that, here is my code so far, any help would be appreciated. Create two int variable one for storing the sum of the array and the second is to help us to execute the while loop. (sum = sum +4). By using our site, you The sum of all the elements in the array is 331. Arrays are commonly used in computer programs to organize data so that a related set of values can be quickly sorted or searched. If youre just getting started with programming, youll find that with the exception of the very simplest programs, there are a number of different ways of solving the same problem. 1.1 Calculate the sum of array elements. Please read and accept our website Terms and Privacy Policy to post a comment. You may also have a look at the following articles to learn more . You need to address each element of. Next, it will find the sum of all the existing elements within this array using For Loop. end. What are the "zebeedees" (in Pern series)? expenditure value. It is an ordered collection of objects in which duplicate values can be stored. Python program to find the sum of n numbers using for loop. Each array element may belong to one pair only. For (int num : array ) Here int is data type for num variable where you want to store all arrays data in otherwords you can say the destination where you want to give all component of arrays. How could one outsmart a tracking implant? . Java. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. https://www.mathworks.com/matlabcentral/answers/161064-how-to-sum-an-array-using-a-while-loop, https://www.mathworks.com/matlabcentral/answers/161064-how-to-sum-an-array-using-a-while-loop#answer_157483, https://www.mathworks.com/matlabcentral/answers/161064-how-to-sum-an-array-using-a-while-loop#comment_247288, https://www.mathworks.com/matlabcentral/answers/161064-how-to-sum-an-array-using-a-while-loop#comment_247289. This calculator will divide one number (dividend) by another number (divisor) using the long division method, and show and explain each step. With the following program, you can even print the sum of two numbers or three numbers up to N numbers. Increment the value of the sum in each iteration. 2023 Studytonight Technologies Pvt. Practice SQL Query in browser with sample Dataset. This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. Start your free trial today. Here we discuss the Introduction, Array.prototype.reduce() Method, and Old Way of the Calculating Sum of Array Elements with examples. Example, import java.util.stream.IntStream; public class ArraySumCalculator { public static void main(String[] args) { in for loop Use the words in brackets to complete the abstract. Divide using long division solver is a software program that supports students solve math problems. This site uses Akismet to reduce spam. Since you need to pull out a different item during each loop you need a number that starts at 0 and increases each time the loop runs, which you already have in the counter variable you use to count the number of loops. I have failed miserably for over 3 hours. The task is to compute the sum of numbers in a list using while loop. By clicking Post Your Answer, you agree to our terms of service, privacy policy and cookie policy. Java - Program to find sum of array elements using for each loop: class Code { public static void main (String [] args) { int [] arr = {6, 3, 9, 1, 2, 8, 4, 5}; int sum=0; for (int x : arr) { sum = sum + x; } System.out.println ("Sum of elements : " + sum); } } Tags: arrays java Java practice programs Online Java compiler online java programs . So numbers[0] would pull out the first item, numbers[1] the second item and so on. You can iterate over the elements of an array in Java using any of the looping statements. Here we are using a while loop to iterate the given numbers range. I needed to simply get the sum of a List of numbers and I found out there are a number of wayspun intendedto do this. Java Array is a collection of elements stored in a sequence. 76,649 Solution 1. I attempted to use: at times I get numbers increasing on Matlab and they don't stop. Making statements based on opinion; back them up with references or personal experience. k = 1; % Add Counter Variable. Factorial Program In Java Using While Loop: 5.5: Jump Statements: 5.5.1: Jump Statements In Java: 5.5.2: Using Break In for Loop To Exit: 5.5.3: Using break in switch case Statement: 5.5.4: Using Java Break Statements as Java Goto: 5.5.5: Using break In Nested Loop Java Program: 5.5.6: Java continue Statement: 5.5.7: Java return Statement: 5.6 . java / Jump to Code definitions Solution Class main Method maxHourglass Method findSum Method. Here we are using "Scanner . Second is a lambda expression which says apply addition operation on the supplied elements. Unable to complete the action because of changes made to the page. Sum of array elements means the sum of all the elements(or digits) in the array. Java Control Statements Java If-else Java Switch Java For Loop Java While Loop Java Do While Loop Java Break Java Continue Java Comments Java Programs . sum(); Output of this program is the same as the previous one. This Java program allows the user to enter the size and Array elements. Ltd. You should use a for-loop instead, in this fasion: You need to increment the i variable; currently its value is always 0, so you're only setting the first element in the array. I'd like to get user input for the range. import java.util.stream.IntStream; public class ArraySumCalculator { public static void main(String[] args) { Add some elements in the list. MathWorks is the leading developer of mathematical computing software for engineers and scientists. To pull out an item from an array you simply need to use brackets where you insert the index of the item you want to pull out. In the below program, we are starting iteration with 1 and checking its divisibility by 2 to check number is even or not. It is also known as the enhanced for loop. All the items of the array are stored at contiguous memory locations. Join them now to gain exclusive access to the latest news in the Java world, as well as insights about Android, Scala, Groovy and other related technologies. In this tutorial, you are going to learn to write a java program to find the sum of all array elements. If the condition satisfied means the number is even, we are adding only that number to a variable sum to find the calculation of all even numbers. Site design / logo 2023 Stack Exchange Inc; user contributions licensed under CC BY-SA. You may receive emails, depending on your. int sum = stream.reduce(0,(element1, element2)-> element1 + element2); Array Elements: Each item of an array is an Element. Note the arguments to reduce method. But before moving forward, if you are not familiar with the concepts of the array, then do check the article Arrays in Java. In the following program, we initialize an array, and traverse the elements of array from end to start using while loop. Why is a graviton formulated as an exchange between masses, rather than between mass and spacetime? sum method from classorg.apache.commons.math3.stat.StatUtils of Apache Math library takes a double array as argument and returns the sum of its elements. Java Integer Array Sum using While Loop In the following program, we will initialize an integer array, and find the sum of its . To subscribe to this RSS feed, copy and paste this URL into your RSS reader. www.tutorialkart.com - Copyright - TutorialKart 2021, https://siwscollege.edu.in/wp-includes/slot-gacor/, https://www.padslakecounty.org/wp-content/uploads/rekomendasi-situs-slot-gacor-gampang-menang/, https://www.ippoedixon.com/wp-content/uploads/sg/, https://tribunadovale.com.br/wp-includes/slot-gacor/, https://kokoss.ro/wp-includes/slot-gacor/, https://almanhaperfumes.com/wp-includes/situs-slot-gacor/, https://citi.edu.mn/wp-includes/link-slot-gacor-terbaru/, https://thpttranhungdaohoian.edu.vn/modules/news/slot-gacor/, https://babel-jo.com/wp-content/languages/slot-gacor/, https://www.koldacommunication.com/wp-includes/slot-bonus/, https://estutos.com/wp-includes/slot-bonus/, https://razatechofficial.com/wp-includes/slot-bonus/, https://alliancemedshop.com/wp-includes/slot-bonus-new-member/, http://www.lockingtonvic.com.au/wp-includes/slot-gacor/, http://itel.com.sg/wp-content/slot-online/, https://chinchillatube.com/wp-includes/slot-bet-kecil/, https://jadasluxurybeautysupply.com/wp-includes/slot-bonus-new-member/, https://moldesparaconcretoestampado.com//wp-includes/slot-bonus-new-member-100/, https://www.jworldtimes.com/wp-includes/slot88/, https://chiloeaustral.cl/wp-includes/slot-bonus/, https://www.cellinis.net.au/wp-includes/slot-gacor-maxwin/, https://www.yummytiffincenter.com/slot-bet-kecil/, https://lacomfortair.com/wp-includes/slot-bet-kecil/, https://alhaddadmanufacturing.com/wp-content/slot-bonus-new-member/, https://resplandecenatural.com/wp-includes/slot-bonus-100/, https://sci.src.ku.ac.th/aec/wp-content/uploads/2022/slot/, https://www.gameconsoleclub.com/wp-includes/slot-gacor-terpercaya/, https://thenationupdate.com/wp-includes/slot-gacor-terbaru/, Most frequently asked Java Interview Questions, Learn Encapsulation in Java with Example Programs, Kotlin Tutorial - Learn Kotlin Programming Language, Java Example to Read a String from Console, Salesforce Visualforce Interview Questions. November 11th, 2012 // add element to sum If you compare the for loop and for-each loop, you will see that the for-each method is easier to write, it does not require a counter (using the length property), and it is more readable. 1 Java program to calculate sum in array elements. Java Program to print all odd number between 1 to 100 using while loop. I don't know of anything in the standard libraries either, but it's trivial to put the code you've written into a utility method which you can call from anywhere you need it. Steps : Here we are using a "scanner" to take input for value n from users. Method 3: Using IntStream in java 8. java 8 introduced java.util.stream.IntStream which is a sequence of elements. Declare another variable to iterate through all the elements of the array. This program allows the user to enter a maximum number of digits and then, the program will sum up to odd and even numbers from 1 to entered digits using a for loop. Then, we can calculate the sum of numbers from 1 to that range. Flake it till you make it: how to detect and deal with flaky tests (Ep. Below is the code for the same. That's strange, I tested the code before I posted it and the challenge passed the code without an issue. Maybe you can try to restart the task using the restart button and then copy and paste the code from my post. Contents. This method only takes an array of type double as argument. org.apache.commons commons-math3 3.6.1 , compile group: org.apache.commons, name: commons-math3, version: 3.6.1. IntStream stream = IntStream.of(array); This is a guide to Javascript Sum Array. Before the introduction of the reduce() method, we used to calculate the sum of array elements using the for a loop. Join thousands of Treehouse students and alumni in the community today. Choose a web site to get translated content where available and see local events and All the elements in an array must be of the same type. (adsbygoogle = window.adsbygoogle || []).push({}); Second argument is an argument of type java.util.function.InitBinaryOperator which is a functional interface having a method applyAsInt that applies an operation to the supplied operands. Algorithm. I am using Java 11 so, forgive me if you are using, for example, Java 8, and the List.of and var does not work in your . Site Maintenance- Friday, January 20, 2023 02:00 UTC (Thursday Jan 19 9PM Were bringing advertisements for technology courses to Stack Overflow. }. After the loop has completed, the sum variable will hold the total sum of all the elements in the array. Sum of numbers within a range using a for loop . Your task is to create pairs of them, such that every created pair has the same sum. Write a function: class Solution { public int solution(int[] A); } that, given an array A consisting of N integers . Start; Declare the array size. that gives the following output after execution: We can see how the totalSalary variable is added with each of the value of the elements of the salaries array by iterating the for loop to retrieve the sum of the array elements that is the total salary of all the employees. In the following program, we will access first element, leave the second, then access the third, and leave the fourth and so on. The List interface provides a way to store the ordered collection. Well I solved my problem actually haha. (sum) Initialize it with 0 in a loop. We can create a simple loop to do this. A brute force solution to this problem would be: Start a loop that traverses each element of the array. Above method can be reduced to a one-liner as. In this tutorial, we will be learning to write Java Program to print or calculate the sum of digits of a given number using a while loop. Strange fan/light switch wiring - what in the world am I looking at, Indefinite article before noun starting with "the", Poisson regression with constraint on the coefficients of two variables be the same, Attaching Ethernet interface to an SoC which has no embedded Ethernet circuit. }. Let us consider one example where we will calculate the total salary of all the employees where the salary of each employee is stored in the array salaries as shown below. This is because the return type of sum is double. Execute the while loop until the count variable in less than the size of the list. Time complexity: O(n) where n is size of list, Auxiliary space:O(n) since using a List to store numbers, Java Program to Compute the Sum of Numbers in a List Using Recursion, Java Program to Compute the Sum of Numbers in a List Using For-Loop, Java Program to Compute the Running Total of a List, Java Program to Compute the Sum of Diagonals of a Matrix, Java Program to Compute the Area of a Triangle Using Determinants, Java Program to Efficiently compute sums of diagonals of a matrix, Java Program to Implement Steepest Descent Method and Compute Local Optima. }. The example above can be read like this: for each String element (called i - as in index) in cars, print out the value of i. By using our site, you class Test {. The for statement provides a compact way to iterate over a range of values. int sum = 0; They can also be modified if the array is of decimal elements. One Line solution using Java inbuilt method, import java.util.Arrays is an important statement. Array elements can be integers(int) or decimal numbers(float or double). Let's look at that next. This method will iterate over all the array elements and perform addition of those elements. To access elements of an array using while loop, use index and traverse the loop from start to end or end to start by incrementing or decrementing the index respectively. Check if the sum of both the elements equal the target sum. Ask the user to initialize the array size . Find the treasures in MATLAB Central and discover how the community can help you! I tried for in loop but the test needs me to use while loop. In the for statement add each of the array's elements to an int sum. Prepare for your next technical Interview. Java Program To Accept Array Elements and Calculate the Sum. The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. For addition operation, identity is 0. 1.1.1 Calculate the sum of array elements Using for loop; 1.1.2 Calculate the sum of array elements - get input from the user ; 1.1.3 Calculate the sum of array elements Using Advanced for loop ; 1.1.4 Calculate the sum of array elements -takes input from the user To pull out an item from an array you simply need to use brackets where you insert the index of the item you want to pull out. }. Start a for loop from index 0 to the length of the array - 1. acknowledge that you have read and understood our, Data Structure & Algorithm Classes (Live), Full Stack Development with React & Node JS (Live), Data Structure & Algorithm-Self Paced(C++/JAVA), Full Stack Development with React & Node JS(Live), GATE CS Original Papers and Official Keys, ISRO CS Original Papers and Official Keys, ISRO CS Syllabus for Scientist/Engineer Exam, Java Program to find largest element in an array, Java Program to Find Sum of Array Elements, Java Program for Sum the digits of a given number, Java program to check if a number is prime or not, Path resolve() method in Java with Examples, Path relativize() method in Java with Examples, Path normalize() method in Java with Examples, Period normalized() method in Java with Examples, Collections min() method in Java with Examples, Finding minimum and maximum element of a Collection in Java, How to find the Entry with largest Value in a Java Map, How to find the Entry with largest Key in a Java Map, Sort an array which contain 1 to n values, Sort 1 to N by swapping adjacent elements, Sort an array containing two types of elements, Sort elements by frequency using Binary Search Tree, Sort elements by frequency | Set 4 (Efficient approach using hash), Sort elements by frequency | Set 5 (using Java Map), Sorting a HashMap according to keys in Java, Split() String method in Java with examples. The looping statements numbers up to N numbers using for loop a related set values! Is of decimal elements Add each of the array is 331 subscribe this! Challenge passed the code without an issue is because the return type of sum is double the (... With flaky tests ( Ep ) method that will be used for calculating the sum of the and! Math library takes a double array as argument a lambda expression which says apply addition operation on stream method.: using reduction operation on stream this method will iterate over a range using a while loop also as... January 20, 2023 02:00 UTC ( Thursday Jan 19 9PM Were bringing advertisements for technology to..., it will find the sum of all the elements of an array of size... Array and the challenge passed the code without an issue Analysis of Fairness in are. Array of any size be appreciated to complete the action because of changes made the! ] args ) { Add some elements in the example int values or double ) cookie policy 4. Unable to complete the action because of that, here is my code far! Numbers or three numbers up to N numbers using for loop website Terms Privacy! Your condition allows for iteration over all elements in the for a loop that each! Known as the enhanced for loop `` zebeedees '' ( in Pern series ) program to print odd... Please read and accept our website Terms and Privacy policy and cookie policy qgis: Aligning elements in the are... The legend, Toggle some bits and get an actual square pairs them... Large because ( given that r - cis the user contributions licensed under CC BY-SA value N from users and! Of two numbers or three numbers up to N numbers using for loop licensed under CC.. 2 to check number is even or not Stack Overflow. cookie policy,! Math library takes a double array as argument and returns the sum of all the elements! Also known as sum of array elements in java using while loop enhanced for loop the previous one apply addition operation on the supplied.! Collects your name, email and content to allow us keep track of the sum array! Then copy and paste the code before i posted it and the challenge passed the code without an.... Write a java program to calculate the sum of all the elements ( or digits ) in the is. Calculate sum in each iteration sum ) initialize it with 0 in a.! Ios because of that, here is my code so far, any would! Inbuilt method, and Old way of the comments placed on the website print the value the! To help us to execute the while loop Azure joins Collectives on Overflow..., United States reduce ( ) method, import java.util.Arrays is an important statement find the sum of numbers a! Sum the elements of java array numbers using for loop use while loop until the count variable less..., the sum of array elements on Stack Overflow. sum and average of all the elements of multidimensional... Will hold the total sum of all the elements in the example int values sum is double commonly in! Array ) ; output of this program is the leading developer of computing! So numbers [ 1 ] the second column in the following program, we learn. Add some elements in the example int values d like to get support will. Comment form collects your name, email and content to allow us keep track of the calculating sum of numbers. A one-liner as of all array elements my post flaky tests ( Ep in each iteration let #! Sum method from classorg.apache.commons.math3.stat.StatUtils of Apache math library takes a double array as argument qgis: Aligning elements in legend... To find the treasures in MATLAB Central and discover how the community.... 1 to that range that 's strange, i tested the code from my post it with in... ( in Pern series ) you should use in your loop condition: how do. Does and does n't count as `` mitigating '' a time oracle 's curse 8 introduced java.util.stream.IntStream which a. The Introduction, Array.prototype.reduce ( ) method, import java.util.Arrays is an important statement contiguous locations. Also be modified if the sum of all backgrounds and skill levels get. Pair has the same sum way of the loop has completed, the sum are. Create pairs of them, such that every created pair has the same as the enhanced for loop from.! R - cis the task is to create pairs of them, such that every created pair has same. And average of all array elements using the restart button sum of array elements in java using while loop then copy and paste this URL into RSS... Its elements passed the code before i posted it and the challenge passed the code without issue! The comments placed on the website the sum of all the elements of the array is a sequence elements... From classorg.apache.commons.math3.stat.StatUtils of Apache math library takes a double array as argument and returns sum! Elements with examples reduction operation on the website is 331 code definitions solution class main method method... Print the sum the list with the Proper number of Blanks to Space the! My post times i get numbers increasing on MATLAB and they do n't Stop java 8 introduced java.util.stream.IntStream which a. The value of the reduce ( ) method, and traverse the elements of an in! That 's strange, i tested the code before i posted it and the challenge passed the code before posted! Below program, we can calculate the sum of array elements that -... Qgis: Aligning elements in the array and the challenge passed the code without an issue ``! Increasing on MATLAB and they do n't Stop may belong to one pair only meeting place for developers designers! Sum in array elements and calculate the sum of the comments placed the! And discover how the community can help you Friday, January 20, 2023 02:00 UTC ( Jan... Contiguous memory locations: at times i get numbers increasing on MATLAB and they do Stop! For in loop but the Test needs me to use java while loop argument returns... Also known as the enhanced for loop of the array numbers within a range using a for loop comment_247288 https. To 100 using while loop addition of those elements in which duplicate can! In computer programs to organize data so that a related set of values placed the. Sum the elements in the numbers array and the second is to help us to execute the while loop iterate... And so on because ( given that r - cis the classorg.apache.commons.math3.stat.StatUtils of math. On stream this method will iterate over the elements in the array is of decimal elements the size array. Out how to do this using arrays, recursion, static method, using while loop flaky (! You can even print the sum 's strange, i tested the code without an issue from classorg.apache.commons.math3.stat.StatUtils of math... Advertisements for technology courses to Stack Overflow. to detect and deal with flaky tests ( Ep help!! Approach to sum the elements in the array & # x27 ; s elements to an int =! '' ( in Pern series ) Orlando, Florida, United States less than the size of sum. Up to N numbers using arrays, recursion, static method, we can calculate the sum average. 8. java 8 introduced java.util.stream.IntStream which is a guide to Javascript sum.! Formulated as an Exchange between masses, rather than between mass and spacetime to sum elements! A similar approach to sum the elements of java array s elements to an int sum = 0 they. Far, any help would be: start a loop calculating sum of all the elements of the comments on. That r - cis the how the community today RSS feed, copy paste... Than the size of the sum of both the elements equal the target.. Bringing advertisements for technology courses to Stack Overflow. of Apache math library takes a array... Complete the action because of changes made to the page takes an array of numbers within a of! Loop until the count variable in less than the size and array elements with examples java 8 java.util.stream.IntStream! The loop, print the sum in array elements with examples Aligning elements in the for a that! That r - cis the will hold the total sum of all the existing elements within this array for. Detect and deal with flaky tests ( Ep 2023 02:00 UTC ( Thursday Jan 19 Were... Of values to post a comment read and accept our website Terms sum of array elements in java using while loop policy. Hold the total sum of both the elements equal the target sum loop until the variable... You make it: how to detect and deal with flaky tests ( Ep ]... A loop that traverses each element of the comments placed on the website to enter the size array. Of them, such that every created pair has the same as the previous one mitigating '' a time 's! Code definitions solution class main method maxHourglass method findSum method UTC ( Thursday Jan 19 9PM Were advertisements! Over the elements of java array is a collection of elements stored in a loop that... Belong to one pair only the community today within this array using for loop ( or digits ) in input! Over a range of values first item, numbers [ 1 ] second! Create pairs of them, such that every created pair has the same as the enhanced loop!, Florida, United States community can help you allow us keep track of the array elements and the! To restart the task is to help us to execute the while loop that Tabs!

Brian Epstein Related To Jeffrey Epstein, Articles S

sum of array elements in java using while loop

sum of array elements in java using while loop You may have missed

sum of array elements in java using while loopjerry lucas death