• 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
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

Verifying explanation

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is it correct that the since the assignment in line 8 evaluates to true, that conditional test is valid??

See below ...

1. boolean a = true;

2. boolean b = false;

3. boolean c = true;

4. if (a == true)

5. if (b == true)

6. if (c == true)
System.out.println("Some things are true in this world");

7. else
System.out.println("Nothing is true in this world!");

8. else if (a && (b = c))
System.out.println("It's too confusing to tell what is true and what is false");

9. else
System.out.println("Hey this won't compile");
 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
To make sense I indented and added curly braces :

Then because b = false nothing will be printed ...
if b changed to true the output will be :
..................................
Some things are true in this world
It's too confusing to tell what is true and what is false
..................................


boolean a = true;
boolean b = false;
boolean c = true;

if (a == true){//if 1
if (b == true){//if 2
if (c == true){//if 3
System.out.println("Some things are true in"+
" this world");
}else {//if 3 's else
System.out.println("Nothing is true in this world!");
}
if (a && (b = c)){ //if 4
System.out.println("It's too confusing to tell"+
"what is true and what is false");
}else { //if 4's else
System.out.println("Hey this won't compile");
}//end if 4's else
}//end if 2
}//end if 1
 
Paper beats rock. Scissors beats tiny ad.
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic