Win a copy of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 this week in the Java in General forum!
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

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
 
WHAT is your favorite color? Blue, no yellow, ahhhhhhh! Tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic