Q&A

Q1:The if statement seems like the one that's most useful. Is it possible to use only if statements in programs and never use the others?
A1: It's possible to do without else or switch, and many programmers never use the ternary operator ?. However, else and switch often are beneficial to use in your programs because they make them easier to understand. A set of if statements chained together can become unwieldy.
Q2:An if statement is described as either a single statement or as a conditional statement followed by another statement to handle if the condition is true. Which is it?
A2: The point that might be confusing is that if statements and other conditionals are used in conjunction with other statements. The if statement makes a decision, ...

Get SAMS Teach Yourself Programming with Java™ in 24 Hours, FOURTH EDITION now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.