Help coderanch get a
new server
by contributing to the fundraiser
  • 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
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

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
 
reply
    Bookmark Topic Watch Topic
  • New Topic