• 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
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

constructors

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
this bit of code produces no output, somebody please explain me why,
public class inter1{
public static void main(String argv[]){
inter1 mi = new inter1();
}
inter1(){
boolean b=true;
if(b=false){
System.out.println("The value of b is"+b);
}
}
}
 
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When you say if(b=false), you are assigning false to b, thus the condition is not met and no output. To get output, either do if(b) or if(b=true). You are assigning true to b once again in the second case.
Hope it helps.
 
sonu shawnee
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Tony,
I overlooked that part entirely.
 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try this
public class inter1{
public static void main(String argv[]){
inter1 mi = new inter1();
}
inter1(){
boolean b=true;
if(b!=false){ // Changed Here
System.out.println("The value of b is"+b);
}
}
}

This will work and this further clarifies things
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic