In this program, what is the importance of x++ ? can I replace with any other or delete permanently ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

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);

26th Mar 2020, 3:47 PM
Gurmeet Singh
Gurmeet Singh - avatar
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/
26th Mar 2020, 4:01 PM
Jayakrishna 🇮🇳