• Post Reply Bookmark Topic Watch Topic
  • New Topic

operatots  RSS feed

 
puneet pruthi
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
i am having problem with this code
class abc{
public static void main(String args[]){
int i=0;
int []a={3,6};
a[i]=i=9;
System.out.println(i+""+a[0]+""+a[1]);
}
}
as the assignment operator works from right to left ,this shud give arrayout of bound error.But it runs smoothly!!
 
Jerry Pulley
Ranch Hand
Posts: 221
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Puneet,
The array access expression is evaluated before the assignment of 9 to i.
Jerry
 
Pratap Reddy
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Puneet
The assignment operator works from left to right. First any variable on left need to complete before you assign the left value. Read JSL.
Answer: a[0] = i = 9; , So it will print 996
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!