• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • paul wheaton
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Tim Holloway
  • Carey Brown
  • salvin francis

IS this question good? why

 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what is the value of j at line 17?
[ June 26, 2002: Message edited by: huanyu zhao ]
 
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by huanyu zhao:


Correct me if I am wrong, wouldn't this thing produce a compiler error at the line that says

since i>10 gives me boolean value which & don't take? Or is it a runtime error since express are evaluated during runtime...either way I thought & is a bitwise operator that only take integer, while boolean is never evaluated as integers.
 
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The value of j would be 1 at line 17.
methodB() will be called only once,i.e in
b=i>10 & methodB(1);
Here, b=i>10 && methodB(2);

i>10 is false,so the methodB() will not be called.
[ June 26, 2002: Message edited by: geetha nagarajan ]
 
Chung Huang
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Never mind, forgot about that short-circut nature
wouldn't j be 2? the call send over 2, and the line says j += k where j is 0 and k is the value send over which is 2.
[ June 26, 2002: Message edited by: Chung Huang ]
 
geetha nagarajan
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
& can take both boolean and integral operands.
&& can be applied to boolean expressions only.
 
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To geetha
I thought the & operand is not short cutted!
only && is short-cutted. I thought the second operand always gets evaluated even if the first operand evaluates to false. but if you use && then if the result can be determined, then the second operand doesn't get evluated?
correct me please.
 
geetha nagarajan
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To Amir,
Yes, && is short-circuited and not &.
Both operands r evaluated in case of &.
 
Ranch Hand
Posts: 182
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
good question huanyu, just one detail:

we always have to be aware of these little errors.
Francisco
 
huanyu zhao
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by geetha nagarajan:
The value of j would be 1 at line 17.
methodB() will be called only once,i.e in
b=i>10 & methodB(1);
Here, b=i>10 && methodB(2);

i>10 is false,so the methodB() will not be called.
[ June 26, 2002: Message edited by: geetha nagarajan ]


oh good! thank you!
 
Ranch Hand
Posts: 114
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The code in your very first post does not the main() properly defined is that a typo???
Coz if it is not the prograom will fail to run right??
 
He's my best friend. Not yours. Mine. You can have this tiny ad:
professionally read, modify and write PDF files from Java
https://products.aspose.com/pdf/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!