• 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
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

weird

 
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Guys......
Check out the code below.
public class MyAr{
public static void main(String argv[]){
long l = 99;
int i = 1;
int j = 0;

j=i<<l;>
System.out.println(j);
}
}
This ocde compiles cleanly and gives an output of 8. What I couldn't understand is how does it compile cleanly without giving an error???
In the statement j=i<<l; 'i' would first be promoted to long and the result of 'i><<l' which would be a long will be assigned to 'j' which is an int. Shouldn't the system give an error message as there is no explicit cast (from long to int) in the statement j=i<<l;>
Thanks in advance...
Shafeeq
 
Ranch Hand
Posts: 147
Android Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I get the following errors:


MyAr.java:7: 'void' type not allowed here

j=i< System.out.println(j);

-----------------------^

MyAr.java:7: incompatible types

found : boolean

required: int

j=i< System.out.println(j);

---^

2 errors
[This message has been edited by Glen Tanner (edited August 08, 2000).]
 
Shafeeq Sheikh
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
public class MyAr{
public static void main(String argv[]){
long l = 99;
int i = 1;
int j = 0;
j = i << l;
System.out.println(j);
}
}
Sorry.... here's the correct version of the code..... I must have 'eaten some parts when I was cut/pasting.....
Any inputs???
Thanks,
Shafeeq
 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The output is prefect right.
99%32 is 3 and i=1, therefore
the result of 1<<3 is 8.

Kevin
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic