• 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
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

Whats the output

 
Ranch Hand
Posts: 225
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

public class MyClass {
public static void main(String [] args) {

System.out.println(x);
}
}
which two will produce the same results when inserted on line 3? (Choose two.)





A
int x = (~25);
B
int x = (10 | 3);
C
int x = (10 >> 2);
D
int x = (10 & 22);
E
int x = (-3 >>> 1);


Hi i thought shift operators are not so much important but i found this code so whats is the output

Thanks in advance
 
Ranch Hand
Posts: 2412
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The best way to work this one is to compute each option to see the outcome.

A. 25 = 11001

~25 11111111111111111111111111100110

B. 10 = 1010

3 = 0011

10 | 3 = 1011

C. 10 = 1010

10>>2 = 0010

D. 10 = 01010
22 = 10110

10 & 22 = 00010

E. 3 = 011

-3 = 11111111111111111111111111111101

-3 >>> 1 = 01111111111111111111111111111110
 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Srinivas,

shift operators are quite important from exam point of view(SCJP 1.4).
You can verify result by running it.

int x = (10 & 22);
and
int x = (10 >> 2);

gives same result. Please let us know the confusion in question as this seems to be straight forward question.
 
srinivas sridaragaddi
Ranch Hand
Posts: 225
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Keith and Jag for the reply

But i am preparing for 1.5 so i wanted to know how much important shift operators are. I thought very less importance is given to shift operators in 1.5 exam. Am i correct.

Any one who is preparing for scjp5 please clarify (i know that it is given in book itslef) does it mean no question on shift operators.

please clarify :roll:
 
Ranch Hand
Posts: 229
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think I read somewhere in the book, it's for 1.4 only not 1.5.
 
I got this tall by not having enough crisco in my diet as a kid. This ad looks like it had plenty of shortening:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic