Relational operators based Output Writing – Computer Sir Ki Class

Login


Lost your password?

Don't have an account ?
Register (It's FREE) ×
  

Login
[lwa]



Solved Problem #JAVA#3682 siteicon   siteicon   siteicon  

Problem Statement - Relational operators based Output Writing

Write output of the following program.

class SP_RelationalOP
{
  public static void main(String[] args)
  {
    float x=2.35f; 
    int y=2;
    System.out.println(x!=y);
    System.out.println(x<y); 
    System.out.println(y>x);
    System.out.println(y>=x);
    System.out.println(y<=x);
    System.out.println(x==2.35);
    System.out.println(x==2.35f);
  }
}

 

Solution

TC++ #3682

Run Output

true
false
false
false
true
false
true

float x=2.35f;  //Float variable x initialised with 2.35
int y=2;            //integer variable y initialised with 2
System.out.println(x!=y); //This is true as x is more than y
System.out.println(x<y);  //This will also be false as x is more
System.out.println(y>x);  //This would again be false as y is smaller
System.out.println(y>=x); //This would also be false is y is smaller and not equal also.
System.out.println(y<=x); //This would be true as y is smaller
System.out.println(x==2.35); //This would be false as 2.35 would be taken double type while x is float type.
System.out.println(x==2.35f); //This would be true as both sides are float type and they are equal

Notes


Share

sunmitra| Created: 3-Mar-2018 | Updated: 27-Nov-2019|






Back