Select the best answer about the following code fragments (a) and (b): (a) if (age System.out.println ("no beer for you"); if (age System.out.println ("BEER!"); 21) く 21) (b) if (age < 21) System.out.println ("no beer for you"); else System.out.println ("BEER");
Select the best answer about the following code fragments (a) and (b): (a) if (age System.out.println ("no beer for you"); if (age System.out.println ("BEER!"); 21) く 21) (b) if (age < 21) System.out.println ("no beer for you"); else System.out.println ("BEER");
Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
Related questions
Question
Expert Solution
Explanation
I run both the code in java, because from analaysing the code its written in java you can see i got output from both the question a and b,
from above example and output we can say that both the conditions are true, now question is which one is better obviously we want to make our code more simple and readable so option b is better option because here we dont need to write the condition, else part is giving us exatly same output as second if in option a.
Step by step
Solved in 2 steps with 2 images
Recommended textbooks for you
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education