Why the occ[4] not icrement or increase | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
- 1
9th Oct 2020, 3:18 PM
born2code
born2code - avatar
5 Answers
+ 1
In you code, instead loop write this and see what happening... for(int i=0; i<n.length; i++) { System.out.println("number "+ n[i] + " is in "+(++occ[n[i]])+ "times "); //occ[n[i]]; } Edit : Rankush int n[]={1,2,5,1,2,3,4,2,4,1}; Initially all values in occ array are 0. Next by this ++occ[ n[i] ], the values changing.. I =0, n[0] = 1, then ++occ[1] causing occ[1] to 1 from 0. I =1, n[1] = 2, then ++occ[2] causing occ[2] to 1 from 0. I =2, n[2] = 5, then ++occ[5] causing occ[5] to 1 from 0. I =3, n[3] = 1, then ++occ[1] causing occ[1] to 2 from 1. I =4, n[4] = 2, then ++occ[2] causing occ[2] to 2 from 1. I =5, n[5] = 3, then ++occ[3] causing occ[3] to 1 from 0. I =6, n[0] = 4, then ++occ[4] causing occ[4] to 1 from 0. I =7, n[0] = 2, then ++occ[2] causing occ[2] to 3 from 2. I =0, n[0] = 4, then ++occ[4] causing occ[4] to 2 from 1. I =0, n[0] = 1, then ++occ[1] causing occ[1] to 3 from 2.
9th Oct 2020, 3:33 PM
Jayakrishna 🇮🇳
0
The program finding how many times a numbers is in from array n and that is telling by occ array. There occ[4] telling that 2 times number is in array n. Not increamenting n[4]...
9th Oct 2020, 3:28 PM
Jayakrishna 🇮🇳
0
Thanks for answering me
9th Oct 2020, 3:42 PM
born2code
born2code - avatar
0
I updated above, see again, if you want more detail. Rankush you're welcome..
9th Oct 2020, 3:47 PM
Jayakrishna 🇮🇳
- 1
Please understand me briefly
9th Oct 2020, 3:28 PM
born2code
born2code - avatar