• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

doubt in explanation dam mock question

 
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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));
}
}
 
Ranch Hand
Posts: 1865
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot dan for your nice mock its very helpful mocks
best wishes
 
Hey cool! They got a blimp! But I have a tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic