+ 2

Explain this code plz...

public class Program { public static void main(String[] args) { int a[]= {1,5,6,2,3,4}; System.out.println(a[a[3]]); } }

16th Jun 2019, 8:07 AM
dharmendra vishwakarma
dharmendra vishwakarma - avatar
2 Respostas
+ 8
This is just based on indexing bro In strings , every element has a specific index. In your string the indexing is like this : { 1 , 5 , 6 , 2 , 3 , 4 } 0 1 2 3 4 5 = indexing This is left to right indexing starting from 0 Now .printIn(a[a[3]]) It first access the 4th element that has index 3 a[3]=2 Now .printIn(a[2]) It then access the 3rd element that has index 2 a[2] = 6 Hence 6 is the output Thanks
16th Jun 2019, 8:21 AM
Prince PS[Not_Active]
Prince PS[Not_Active] - avatar
+ 2
Thankyou Prince PS it helps
16th Jun 2019, 8:24 AM
dharmendra vishwakarma
dharmendra vishwakarma - avatar