Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

doubt in explanation dam mock question

 
zaghal mohd
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a doubt in explanation dam mock question... this is the question:
class Lg {
public static void main (String s[]) {
int i = 1 | 2 ^ 15 & 7 ^ 13 | 2;
System.out.println(i % 5);
}
}
the answer its ok but in explanation
(1 | (2 & (3 >> ((1 / 2) + 3)))), (1 | (2 & (3 >> ((0) + 3)))), (1 | (2 & (3 >> (3)))), (1 | (2 & (24))), (1 | (0))=1
I think (3 >> ((0) + 3)))) will give you zero not 24
Correct me please
 
zaghal mohd
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry folks I wrote wrong question her its
class M {
static int m(int i) {
System.out.print(i + ", ");
return i;
}
public static void main(String s[]) {
int i=0;
int j=0;
System.out.print(m(++i) | m(++i) & m(++i) >> m(++j) / m(++j) + m(++j));
}
}
 
Dan Chisholm
Ranch Hand
Posts: 1865
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Last Sunday, the correction was uploaded to the September 27 version.

Answer "b. Prints: 1,2,3,1,2,3,1"

Java evaluates expressions from left to right while respecting operator precedence. (1 | (2 & (3 >> ((1 / 2) + 3)))), (1 | (2 & (3 >> ((0) + 3)))), (1 | (2 & (3 >> (3)))), (1 | (2 & (0))), (1 | (0))=1

[ October 09, 2002: Message edited by: Dan Chisholm ]
 
zaghal mohd
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot dan for your nice mock its very helpful mocks
best wishes
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic