Lowest price ever! Learn Generative AI for 48% less!
Get my discount0
In this program, what is the importance of x++ ? can I replace with any other or delete permanently ?
int [ ] myArr = {6, 42, 3, 7}; int sum=0; for(int x=0; x<myArr.length; x++) { sum += myArr[x]; } System.out.println(sum);
1 Answer
+ 1
If you remove that it will be Infinite loop...
Please read the for loop tapic.. Explanation is clearly given..
If you don't understand, you can ask again...
That is used to update x value for next iteration..
x++; x value updated by adding 1
x+=2; x value increamented by 2
....
https://www.sololearn.com/learn/Java/2147/