 अँई संजे्गुप्ता अज्एस आप ओए बिरने साप्रे ॥ गरे दुवों । आआद प्चों पुज्ग करभा ہے । अच्ँना सकना गर लिए सुप्वेद्डा लिए । इस और त़ो दीड तपाजद बाचा कढद kit now i am going to define a class whose name is array sum inside this class i am going to implement definition of main method inside this main method i will be writing the code which will read elements from the user and those elements will be stored in one d array and then i have to print some of those elements with the help of java program so first of all i am going to declare an array, variable n, variable s and variable i for sum i have used s variable which is initialized with 0 now i am going to create instance of this scanner class that is input so this input will be used to read values from user and system.n will decide that the input will be received from console now here you can see i have just declared an array i have not created memory blocks for this array so before creating memory i have to read size of array from user so with the masses and the size of array user will be entering size of array so that will be received through this method next int and the value will be stored inside n variable so in this program user is deciding how many elements user want to store inside the array so that size will be decided by this n variable now after reading size i can create memory blocks for the array so you can see line number 11 this line number 11 is creating n memory blocks for array ar now i am going to receive elements from user so i am writing a loop which is starting from 0 its termination condition is i less than ar.length this length is an attribute of array which provides size of the array automatically now to read values again i am using input.next int method so input.next int will be receiving values one by one and the values will be stored inside ar so line number 15 will receive elements from user and this loop will repeat n times so total n elements will be received and their values will be stored inside the array now i have to calculate their sum so just after reading the value i can add that into s variable so line number 16 will add all the elements provided by the user into s so here two operations are performing the entered element is storing in the array and as well as its addition is storing into s variable now after completion of this loop i can print the sum on output screen with line number 80 sum of array will be displayed on output screen so this way i have implemented the complete code in front of you you will see n numbers from user and sum of those numbers will be printed on output screen with help of 1d array in java now i have saved this code with control plus s you can see name of file which is array sum it is saved in d drive inside java folder so for compilation and execution i am going to open command prompt you can see i have moved to d drive and java folder after moving to specific location i have to compile the code for that purpose i have used the command java c array sum.java so here i have implemented that statement and it is not showing any error it means source code is written correctly now we can execute our code for execution i have type java array sum so just after execution code will ask size of array so i have entered size as 5 after entering size it will ask for elements so i have entered 5 elements 1 2 3 4 5 so after complete input automatically sum of all the elements will be displayed so you can see code is showing sum equals to 15 which is sum of 1 plus 2 plus 3 plus 4 plus 5 so this time i have entered 5 again i am going to execute the code and i am entering size as 10 so this time it is asking for 10 elements so i am entering 10 times 1 you can see the output it is showing sum equals to 10 so it means this array is working dynamically whatever size of element you want to enter in the array you can do with the help of this program so in case of java array works dynamically but in case of c and c plus plus array can work statically or dynamically in both the ways but in case of java you can directly use array in form of dynamic so the benefit of dynamic array is that you can provide size of array at execution time and as per the size you can enter the elements for processing so i hope you have understood how we can use one d array in java to print sum of the elements if you want to follow me you can subscribe my youtube channel thank you for watching this video