• 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

abt less than or equal to

 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,
given the codition,
if(x<=y)
{
..
}
where x=5,y=5.
how come the expression evaluates to false?
please let me know,
thanks in adv
 
Sheriff
Posts: 3341
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
More information is needed to answer this. Could you please post code that shows this problem.
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
dear friend,

Compound assignment operators,when applied in an expression like
x<=y appear to behave like x = x < y; Since both x and y are 5
it returns false.
 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Bhuvana Dhruva:
hi,
given the codition,
if(x<=y)
{
..
}
where x=5,y=5.
how come the expression evaluates to false?
please let me know,
thanks in adv


- What are the type declarations for these? Please give the correct problem description. For the case given below:
int x = 5;
int y = 5;
if (x <= y) ... here x <= y definitely evaluates to true!
HTH
 
Carl Trusiak
Sheriff
Posts: 3341
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Viji:
- What are the type declarations for these? Please give the correct problem description. For the case given below:
int x = 5;
int y = 5;
if (x <= y) ... here x <= y definitely evaluates to true!
HTH


This is why I ask for more program information. You are correct Viji. However if the program is

The if test now returns false even though 15.3/3.1 is obviously 5.
The problem is floating point math. The actual result of this operation is 4.935483870967742 and is less than 5.
 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I tried with the following code and it prints "working nice"
public class lessthan_or_equalto{
public static void main(String args[]){
int i = 5;
int j = 5;
if(i<=j){
System.out.println("working nice");
}
}
}
reply
    Bookmark Topic Watch Topic
  • New Topic