• Post Reply Bookmark Topic Watch Topic
  • New Topic

operator demo  RSS feed

 
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
class OperatorDemo
{
static int m(int i)
{
System.out.print(i+",");
return i;
}
public static void main(String[] args)
{
m(m(1)+m(2)%m(3)*m(4));
}
}
output:1,2,3,4,9,
how it is getting that output? please explain
 
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
m(1) prints "1,"
m(2) prints "2,"
m(3) prints "3,"
m(4) prints "4,"


2%3 = 2
=> 2%3*4 = 8
=> 1+2%3*4 = 9

m(9) prints "9,"

Therefore you get: "1,2,3,4,9,"
 
srikanth arroju
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!