• 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

operator flow

 
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi
can any one explain this program this is from k & B book form chapter operators self test

class Comp2
{
public static void main(String[] args)
{
float f 1 = 2.3 f;
float [] [] f2 = {{42.0f} , {1.7f,2.3 f},{2.6f,2.7f}};
float [] f3 ={2.7 f};
Long x = 42 L;
// insert code here
System.out.println("true");
}
}

And the following five code fragments :
F1. if(f1==f2)
F2. if(f1==f2[2][1])
F3. if(x==f2[0][0])
F4. if(f1==f2[1,1])
F5 if(f3==f2[2])

o/p
Threeof them will compile , only one will be true

thanks in advance
 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
class Comp2
{
public static void main(String[] args)
{
float f 1 = 2.3 f;
float [] [] f2 = {{42.0f} , {1.7f,2.3 f},{2.6f,2.7f}};
float [] f3 ={2.7 f};
Long x = 42 L;

// insert code here
if(f1==f2) //Error because you are comparing an array to an element
if(f1==f2[2][1])//compiles and no output becoz f2[2][1] value is 2.7f
if(x==f2[0][0])//compiles and gives the output true
if(f1==f2[1,1])//syntax error because it should be f2[1][1] not f2[1,1]
if(f3==f2[2])//compiles but no output becuase you are comparing address with value
System.out.println("true");
}
}


so three statements compile and one gives the output "true"
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic